Left join in SQL helps combine data from two tables. One can begin writing a query along the lines of select data from a table. The query is then followed by 'left join' keyword and the second table name whose data needs to be combined with the first table. Then there is an on clause which joins the data between the two tables based on common values between similar fields in the two tables.
In the below example we have a table named 'name'.
Our second table would be a table named 'age'.
The empID (employee ID) column is the common factor between the two tables. We will thus perform a join on these columns. The output should be a combination of the two tables. Hence the output must contain the columns 'empID', 'name' and 'age'. We will leverage the concept of left join as shown below to achieve our goal. Note that in a left join all records from the left hand table are returned while matching values are returned by the right hand side table.
No comments:
Post a Comment