Friday, February 5, 2010

MySQL JOIN tip

Perbezaan SQL Query dibawah

select 
        * 
from 
        table_A
LEFT JOIN 
        table_B ON table_A.tba_id = table_B.tbb_tbaid
WHERE
        table_B.tbb_year = '2009'
SQL diatas akan mengembalikan baris yg menepati WHERE condition.

select 
        * 
from 
        table_A
LEFT JOIN 
        table_B ON table_A.tba_id = table_B.tbb_tbaid AND table_B.tbb_year = '2009'
Manakala SQL diatas ini pula akan mengembalikan semua baris dari table_A dan baris dari table_B yg menepati condition di JOIN query.

No comments: