I often see people who write SQL like this:
SELECT * from TableA LEFT OUTER JOIN TableB ON (ID1=I2)
I myself write simply:
SELECT * from TableA LEFT JOIN TableB ON (ID1=I2)
To me the "OUTER" keyword is like line noise - it adds no additional information, just clutters the SQL. It's even optional in most RDBMS that I know. So... why do people still write it? Is it a habit? Portability? (Are your SQL's really portable anyway?) Something else that I'm not aware of?
Left Outer Join : The left join operation returns all record from left table and matching records from the right table. On a matching element not found in right table, NULL is represented in that case.
RIGHT JOIN - Returns all rows from the right table (the table after the JOIN keyword). For rows that have a match in the left table, it returns the values from the left table; for rows without a match in the left table, it fills the missing values with NULLs.
2. 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.
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
OUTER
really is superfluous, as you write, since all OUTER
joins are either LEFT
or RIGHT
, and reciprocally all LEFT
or RIGHT
joins are OUTER
. So syntactically it's mostly noise, as you put it. It is optional even in ISO SQL. As for why people use it, I suppose some feel the need the insist on the join being OUTER
, even if the left-or-right keyword already says so. For that matter, INNER
also is superfluous!
YES
It just make things clearer in my opinion - the clearer and more obvious you state your intent, the better (especially for someone else trying to read and understand your code later on).
But that's just my opinion - it's not technically needed, so you can use it - or leave it.
No. I use
There is no ambiguity for me.
One thing that several months on Stackoverflow has shown me is how much SQL is written and / or maintained by people with no previous exposure to SQL or relational databases at all.
For that reason, I think that the more explicit you can be the better off the next programmer is going to be when looking at your code.
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