On 02/20/2012 10:16 PM, Puneet Kishor wrote:
Could someone please shed some light on this mystery for me?

        1.      SELECT Count(*) FROM a;
                329686

        2.      SELECT Count(*) FROM a WHERE a.col IS NULL;
                3

        3.      SELECT Count(*) FROM b;
                6268

        4.      SELECT Count(*) FROM b WHERE b.col IS NULL;
                0

        5.      SELECT Count(*) FROM a LEFT JOIN b ON a.col = b.col;
                329743

        6.      SELECT Count(*) FROM a LEFT JOIN b ON a.col = b.col WHERE a.col 
IS NOT NULL;
                329740

Of course, given #5, #6 is as expected because of #3.

But, why is #5 329743 and not 329686? Where are the extra 57 rows coming from? 
I thought a LEFT JOIN was supposed to include *all* the rows from the left 
table with NULLs for the columns of the right table where there was no match. 
So, at most, the resulting table would have as many rows as the rows in the 
left table. Certainly not more.

Seems like my understanding is wrong.

Perhaps there exist some a.col values for which there is
more than one row in b where (a.col=b.col).
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to