1. 程式人生 > >LEFT JOIN 資料庫左連線查詢SQL

LEFT JOIN 資料庫左連線查詢SQL

 -- 普通查詢
SELECT T1.NAME , T2.ORDERNO
  FROM TABLE_NAME1 T1 , TABLE_NAME T2
 WHERE T1.ID = T2.T1_ID
   AND T1.STATUS = '1';
-- LEFT JOIN查詢
SELECT T1.NAME , T2.ORDERNO
  FROM TABLE_NAME1 T1
  LEFT JOIN TABLE_NAME T2
  ON T1.ID = T2.T1_ID
  AND T1.STATUS = '1';
註釋:LEFT JOIN 左連線查詢會以主表為查詢主體,查詢出另外一張表相對應的資料行,即使沒有資料也會返回空的資料行!