廣告

2024 年 3 月
 123
45678910
11121314151617
18192021222324
25262728293031

彙整

SQL語法 Left Join

看科學家研究,人會覺得走在左邊的人比較有男(女)人味,因此想泡妞的請走在女伴的左邊……………不是沒有道理的,台灣屬於靠右邊走的習慣,如果男士在女生左邊,會有保護女生讓女生走比較路邊比較安全的感覺……………………….再說連電腦SQL語法也是要你在左邊呢!!!!

 

昨天去書店剛好看到有介紹Join的書翻了一下,發現 left join 正符合我的需求,試了三個Table的 left Join一次把我要的都列表出來,省了另外兩個額外查詢,看文獻也說使用join比較有效率。

select g.*, cbas.custid, cbas.cmpabv, cntc.cntcid, cntc.phone from dbo.gdsinfomt g left join dbo.custbas cbas on (g.Agent = cbas.custid) left join dbo.custcntc cntc on ((g.Agent = cntc.custid) and (cntc.cntcid = substring(g.declno,1,2))) where g.senddate >= ‘20100128’ and g.senddate <= ‘20100128’ […]