SQL语句连接查询问题

select * from A join B on A.id in (B.sid);
怎么实现连接查询的时候,像where一样用in来做连接两张表的条件

回答

如果我没理解错你的问题的话,你这个直接用等于就可以了
select * from A join B on A.id=B.sid

如果你只是想查询A表的数据,那么你可以这样
select * from A where Id in (select sid from B)

select * from A where exists (select 1 from B where B.sid=A.Id)

以上是SQL语句连接查询问题的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>