Some SQL code:
SELECT *
FROM table1 tab1
LEFT OUTER JOIN table2 tab2 ON (tab1.fg = tab2.fg)
LEFT OUTER JOIN table4 tab4 ON (tab1.ss = tab4.ss)
INNER JOIN table3 tab3 ON (tab4.xya = tab3.xya)
LEFT OUTER JOIN table5 tab5 ON (tab4.kk = tab5.kk)
I know what different types of JOINs do, but what I'd like to know is: for each JOIN, which table assumes the role of the "LEFT" table? Will table1
always have the role of the "LEFT" table?
We use the SQL OUTER JOIN to match rows between tables. We might want to get match rows along with unmatched rows as well from one or both of the tables. We have the following three types of SQL OUTER JOINS. SQL Full Outer Join SQL Left Outer Join SQL Right Outer Join Let’s explore each of SQL Outer Join with examples. SQL Full Outer Join
Right Outer Join : The right join operation returns all record from right table and matching records from the left table. On a matching element not found in left table, NULL is represented in that case. 3. Full Outer Join : The full outer Join keyword returns all records when there is a match in left or right table records.
Here we are going to implement the concept of multiple joins. Multiple joins can be described as a query containing joins of the same or different types used more than once, thus giving them the ability to combine multiple tables.
SQL LEFT OUTER JOIN 1 It gives the output of the matching row between both the tables 2 If no records match from the left table, it also shows those records with NULL values More ...
They are processed in top-to-bottom order, with the joins all associating to the "whole" of the prior FROM clause.
All things being equal:
However, the problem with this query
SELECT *
FROM table1 tab1
LEFT OUTER JOIN table2 tab2 ON tab1.fg = tab2.fg
LEFT OUTER JOIN table4 tab4 ON tab1.ss = tab4.ss
INNER JOIN table3 tab3 ON tab4.xya = tab3.xya
LEFT OUTER JOIN table5 tab5 ON tab4.kk = tab5.kk
Is that the INNER JOIN with table3 uses a condition that REQUIRES tab4 to get involved, making it virtually a mandatory link to retain records from the left part, so in total tab1/tab4/tab3 have to successfully join, with tab2 and tab5 optional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With