MySQL subquery and connection operation notes

Source: Internet
Author: User

There is a connection operation between the SQL statements, which must be used in some complex data operations. Simply put, the result of an SQL statement can be part of a connected SQL operation. SQL Structured query statements, subqueries refer to all SQL operations, not a single SELECT statement.

1. Generated by comparison operators:

SELECT user_name,user_idfromWHERE>=(SELECTROUND( AVG (age),0 from users);

You can use Any,some,all to make queries.

SELECT user_name,user_idfromWHERE>= any (SELECT  ROUND(AVG(age),0 from users);

2. Generated by [NOT] In/exis

  

SELECT user_name,user_idfromWHERE>= not in (SELECT  ROUND(AVG(age),0 from users);

  

3. By insert ... Select generates

 create  table   Tdb_goods_brands (brand_id  smallint  UNSIGNED primary   Auto_increment, brand_name  varchar  (40 ) not  null  )  select  brand_name from  tdb_ Goods group  by  brand_name 
UPDATE tdb_goods  INNERJOINon=SET= brand_id;

MySQL subquery and connection operation notes

Related Article

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.