Multi-to-many queries, three-table queries, evaluate mysql statements for common applications: articles and tag data tables, and then query a tag, such as "technology", to query all technical articles.
Article table article:
Aid, title, content ------------------------------------- 1 Qt assists in cross-platform application development, 2 Qt assists in cross-platform application development, 3 Qt assists in cross-platform application development, and 4 Qt assists in cross-platform application development.
Label table tags:
Tid, tname -------------------------------- 1 life 2 technology 3 Technology 4 Entertainment
Article tag relationship table art_tags:
aid,tid----------------------------1 11 21 32 12 32 43 13 23 44 14 2
Then, search for the keyword "technology" based on the tag and display the articles 1, 3, and 4.
Reply to discussion (solution)
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
At. tid = 2? This cannot be known in advance. The user inputs the Chinese character "technology"
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 =''
Thank you!
The original where statement can also be written like this.