欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

这个sql如何关联2张表

程序员文章站 2024-01-10 18:33:25
...
原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