SELECT A.ID,B.TEL FROM A LEFT JOIN B ON A.ID=B.AID
在B表中一个AID对应多个TEL,在这我只想返回和AID对应的第一个TEL,不使用游标的情况下,怎么写这个SQL语句
我想写一SQL,从B表中得到每个AID和TEL的对应关系,TEL只取ORDER BY B.ID ASC
时对应AID的第一个,怎么写呀?
在B表中一个AID对应多个TEL,在这我只想返回和AID对应的第一个TEL,不使用游标的情况下,怎么写这个SQL语句
我想写一SQL,从B表中得到每个AID和TEL的对应关系,TEL只取ORDER BY B.ID ASC
时对应AID的第一个,怎么写呀?
FROM A
LEFT JOIN (select AID,Min(TEL) AS TEL from B group by AID) AS T ON A.ID=T.AID
from A as T
from A as T
from A as T
order by a.ID ASC
where not exists(select 1 from b where b1.aid = aid and b.id)
SELECT A.ID,B.TEL FROM A LEFT JOIN B b1 ON A.ID=B.AID
where not exists(select 1 from b where b1.aid = aid and b.id > id)
SELECT A.ID,B.TEL FROM A LEFT JOIN B b1 ON A.ID=B.AID
where not exists(select 1 from b where b1.aid = aid and b.id)
---------------------
沒寫完吧
from a left join (select aid,tel = min(tel) from b group by adi) b on a.id = b.aid