Hello @Vivek Singh ,
Welcome to the Microsoft Q&A platform.
As per my repro, above two methods works as excepted. When you say it doesn't provide any result - could you please provide more detailed screenshot along with the sample data which you are trying and details about the databricks runtime version.
I had tested this with the sample data on databricks runtime version - 8.2 (includes Apache Spark 3.1.1, Scala 2.12)
Method1: To explain you in detail, I had created two tables named
tableoneasemployee,tabletwoasdepartment, anditemcodeasdeptnowith the following data as shown below:
Result of the method1 are as shown below:
Note: When you the join statement it will return deptno from both the tables.
In order to avoid the
deptnofrom both the tables, you need to useInner Joinas shown below:
-- Use employee and department tables to demonstrate inner join.
SELECT id, name, employee.deptno, deptname
FROM employee INNER JOIN department ON employee.deptno = department.deptno;
For more details, refer Azure Databricks - Joins examples.
Method2: Using dataframes, to explain you in detail, I had created two tables named
tableoneasemployee,tabletwoasdepartment, anditemcodeasdeptnowith the following data as shown below:
Result of the method2 are as shown below:
Hope this helps. Do let us know if you any further queries.
------------
Please don’t forget to Accept Answer and Up-Vote wherever the information provided helps you, this can be beneficial to other community members.