SQL JOINS EXAMPLES:
Below are two tables #A and #B, There are A_id and B_id columns in the tables respectively. We have inserted a few values in both the tables. Please note that 50 is the common value in both tables.
INNER JOIN:
Matching records from both the tables will be the output:
LEFT OUTER JOIN:
All records from LEFT table and Matching records from Right table. NULL where the condition doesn't match:
RIGHT OUTER JOIN:
All records from RIGHT table and Matching records from LEFT table. NULL where the condition doesn't match:
FULL OUTER JOIN:
All records from both tables, Matching records from both tables and NULL wherever no match.
CROSS JOIN:
Cartesian product of both tables: 4*4 = 16 records in this case. Please note that there will be no condition in this case.
UNION:
Duplicate matching records entries are removed. All other records are union.
UNION ALL:
Duplicate entries will be there in this case.
No comments:
Post a Comment