Home > Article > Backend Development > 多对多的查询,三表查询,求mysql语句
普通应用:文章和标签的数据表,然后查询某个标签,如“技术”,能够查询出所有技术类的文章。
文章表article:
aid, title,content-----------------------------------------1 Qt助力跨平台应用开发,势不可挡2 Qt助力跨平台应用开发,势不可挡3 Qt助力跨平台应用开发,势不可挡4 Qt助力跨平台应用开发,势不可挡
tid,tname--------------------------------1 生活2 技术3 科技4 娱乐
aid,tid----------------------------1 11 21 32 12 32 43 13 23 44 14 2
select a.* from article as a left join art_tags at on at.aid=a.aid where at.tid=2
select a.* from article as a left join art_tags at on at.aid=a.aid where at.tid=2
select * from article where aid in(select aid from art_tags where tid in(select tid from tags where tname='技术'));
select a.* from article a left join art_tags b on a.aid=b.aid left join tags c on c.tid=b.tid where b.tname='技术'
谢谢!
原来where也可以这么写