MySQL has 3 seed queries, including, where type, from and exists types.
where sub-query
Where followed by a conditional expression, the condition is true when the row is fetched, where the subquery refers to the inner layer of the query result set of the SELECT statement to act as a conditional expression behind the where of the outer SELECT statement, for example, to query the latest item under each column, select goods _id,cat_id,goods_name from goods where goods_id on (select Max (goods_id) from goods Group by cat_id); Note that the inner SELECT statement can only write one column, and if it is multiple columns it will error, for example, select Max (goods_id), cat_id from goods Group by cat_id) cat_id This column is not possible.
From sub-query
A from-type subquery is a query result set of the inner SELECT statement that acts as a new table for the outer SELECT statement, for example, or to query the newest item under each column, select * FROM (select Goods_id,cat_id,goods_name From goods ORDER by GOODS_ID desc,cat_id ASC) as TMP GROUP by cat_id; The inner table must be named with AS, otherwise it will be an error.
Exists sub-query
The exists sub-query is similar to in usage, for example, to query for a product column, select * from category where exists (select * from goods where goods.cat_id=category.cat_id ), or can be implemented with in, select * from category where cat_id in (select cat_id from goods);
MySQL 3 seed Query