Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you use the OUTER keyword when writing left/right JOINs in SQL?

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?

like image 269
Vilx- Avatar asked Nov 16 '09 11:11

Vilx-


People also ask

What is LEFT OUTER JOIN in SQL?

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.

What is the use of right join in SQL?

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.

What is RIGHT OUTER JOIN in MySQL 2nd edition?

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.

What are the different types of SQL outer joins?

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


4 Answers

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!

like image 129
Arthur Reutenauer Avatar answered Oct 17 '22 14:10

Arthur Reutenauer


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.

like image 24
marc_s Avatar answered Oct 17 '22 14:10

marc_s


No. I use

  • JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL OUTER JOIN
  • CROSS JOIN

There is no ambiguity for me.

like image 3
gbn Avatar answered Oct 17 '22 15:10

gbn


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.

like image 3
Larry Lustig Avatar answered Oct 17 '22 13:10

Larry Lustig