Rumah > Artikel > pembangunan bahagian belakang > 这个sql如何关联2张表
原sql语句为:
SELECT * from ( SELECT DISTINCT *, year( from_unixtime(time ) ) year, month( from_unixtime(time ) ) month FROM A表 WHERE id = 1) as a WHERE is_del =0 AND year = 1 AND month = 1 order by time DESC
现在我想关联B表.如何查询?
A表.id=B表.id
SELECT * from ( SELECT DISTINCT *, year( from_unixtime(time ) ) year, month( from_unixtime(time ) ) month FROM A表 WHERE id = 1) as a , B表 b WHERE a.id=b.ai and is_del =0 AND year = 1 AND month = 1 order by time DESC