SELECT a.*,b.custom_name FROM zqwl_receipt a , zqwl_custom b LEFT JOIN b WHERE a.id= b.id
怪我咯2017-04-17 18:00:22
left join
的用法一般是先查詢主表再join其他表的,例如
select a.*, b.custom_name from zqwl_receipt a
left join zqwl_custom b on a.id = b.id
如果你希望a、b兩個表結合查詢的結果再做關聯查找的話,或許可以用子查詢的方式
select * from (
select a.*, b.custom_name from zqwl_receipt a, zqwl_custom b where a.id = b.id
) t
left join zqwl_custom t2 on t2.id = t.id
但是如果寫出這樣的語句來,最好要要思考a, b兩個表的設計問題,
或者這完全就是沒有必要的
黄舟2017-04-17 18:00:22
沒有 from 表
沒有 on 來篩選這兩個表的關係。
SELECT zqwl_receipt.*,zqwl_custom.custom_name from zqwl_receipt LEFT JOIN zqwl_custom on zqwl_custom.欄位= zqwl_receiptwl_custom on zqwl_custom.欄位= zqwl_receiptwl_custom
on zqwl_custom.字段= zqwl_receipt.wl_custom 🎜on zqwl_custom.欄位= zqwl_receipt.T.