MySQL 3 seed Query

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.