left join on多個條件怎麼寫

2021-10-09 05:25:39 字數 419 閱讀 1298

有時我們不僅需要用乙個欄位去關聯,還希望兩個表的兩個欄位都是一樣的,這時候可以這樣寫

select * from(

select id,name,code from table1

) aleft join

(select id,name,code from table2

) bon a.id = b.id and a.code = b.code

有時候on出錯的話,可以用cast

on cast(a.id as varchar(40)) = cast(b.id as varchar(40))

and cast(a.code as varchar(40)) = cast(b.code as varchar(40))

inner join right join 亦然~

你學廢了嗎

SQL語法 left join on 多條件

重點 先匹配,再篩選where條件。本文將通過幾個例子說明兩者的差別。表1 product idamount 1100 2200 3300 4400 表2 product details idweight exist222 04441 55506 661單個條件 select from produc...

left join on 和where條件的放置

left join裡面帶and的查詢 select p.pname,p.pcode,s.saletime from product as p left join sales detail as s on s.pcode p.pcode and s.saletime in 2012 07 23 201...

left join on 和where條件的放置

select from tdleft join select case id as sup case id count supervise number from td kcdc case sup info group by case id sup on sup.sup case id td.cas...