Multi-to-many queries, three-table queries, mysql statement This post was last edited by setoy from 2015-02-0615: 11: 52 Common Application: Data tables of articles and labels, then query a tag, such as "technology", to query all technical articles. Article table article: & nbsp; aid, & nbsp; title, content ------------ multi-to-many queries, three-table queries, evaluate mysql statements
This post was last edited by setoy at 15:11:52 on
Common applications: Data tables of articles and tags, and then query a tag, such as "technology", to query all technical articles.
Article table article:
Aid, title, content
-----------------------------------------
1 Qt facilitates cross-platform application development, which is unstoppable
2 Qt assists in cross-platform application development, which is unstoppable
3 Qt assists in cross-platform application development, which is unstoppable
4 Qt assists in cross-platform application development, which is unstoppable
Label table tags:
Tid, tname
--------------------------------
1 Life
2 Technology
3 Technology
4 Entertainment
Article tag relationship table art_tags:
aid,tid
----------------------------
1 1
1 2
1 3
2 1
2 3
2 4
3 1
3 2
3 4
4 1
4 2
Then, search for the keyword "technology" based on the tag and display the articles 1, 3, and 4.
------ Solution ----------------------
Select a. * from article as a left join art_tags at on at. aid = a. aid where at. tid = 2
------ Solution ----------------------
Select * from article where aid in (select aid from art_tags where tid in (select tid from tags where tname = ''));
------ Solution ----------------------
Select a. * from article
Left join art_tags B on a. aid = B. aid
Left join tags c on c. tid = B. tid where B. tname = 'technical'