Maison  >  Article  >  développement back-end  >  这个sql如何关联2张表

这个sql如何关联2张表

WBOY
WBOYoriginal
2016-06-23 14:05:31893parcourir

原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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn