Monday, November 2, 2009

Keep in mind when using Left Join

The WHERE clause would be false in the following query if tableB.column1 were NULL:

SELECT * FROM tableA LEFT JOIN tableB ON (column1) WHERE tableB.column2=5;

Therefore, it is safe to convert the query to a normal join:

SELECT * FROM tableA, tableB WHERE tableB.column2=5 AND tableA.column1=tableB.column1;