Is it possible to make Outer join with old style code

  • Hi,

    I'm dealing with old style code that do joins without JOIN keyword like in a piece below, in such case is it possible somehow to implement OUTER functionality ?

    select t1.c1, t1.c2, T2.COL3 from t1, T2

    where t1.c1 = T2.Col1

  • The SQL89 standard for outer joins is *= or =* depending of you want a left or right outer join.

    eg.

    select t1.c1, t1.c2, T2.COL3 from t1, T2

    where t1.c1 =* T2.Col1

  • Above sample is equal to an INNER JOIN. To get the FULL OUTER JOIN you'll just need to remove the WHERE clause. To get a LEFT (or RIGHT) OUTER JOIN change the WHERE clause to "WHERE columnname IS NOT NULL).

    But since you are rewriting the query it is much better (readability, following standard) to user the JOIN syntax.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • That is incorrect, if you remove the WHERE clause, you're getting a cartisian product or cross join (every record from left joined with every combination from the right). A full outer join will return all rows from both tables, big difference.

  • Andrew G (6/26/2013)


    if you remove the WHERE clause, you're getting a cartisian product or cross join

    Of course! You're right... and I will get some coffee to wake up 😉

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • Caffeine is good 😀

    But I do agree, use the SQL92 (OUTER JOIN) standard for joins, it's supported in SQL2000 and higher, so can't see any reason to use the old code.

  • Thanks, I'll try =+

    Forgot to tell that i'm on MS SQL Server

    Tx

    M

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply