Connection query: Select Table_b.type,table_b.title,table_b.content,table_b.author from table_a left join table_b on table_a.type = Table_b.type where table_a.id = 1;
Subquery: Select Type,title,content,author from table_b where type = (select type from table_a where id = 1);
If an ID corresponds to more than one type, use Select Type,title,content,author from Table_b where type in (select type from table_a where id = 1);
The results are as follows:
Using the most common query (not in the form of a relational table or an intermediate table) can also get the same effect, as follows:
SELECT * from table_b WHERE type = ' a ';
So why would it take so much effort to build a relational table?
The difference between the two approaches is that the second one queries all records of Class A directly in the detail table, and the first is obtained by the parameter ID to category A, and then to the detail table for all Class A records.
I personally believe that the reasons may include: 1, join the relationship table or the intermediate table, can make the relationship between the data more explicit; 2, the front-end is passed by an ID parameter, backstage only through this ID parameter to carry out a series of queries, to a certain extent, to ensure the security of the data.
MySQL Query relationship Query