MySQL simple syntax (8)

Subqueries

- Use the keyword IN sub-query
- Example:
- explanation: brackets for sub-queries, we first found table3 this table inside presence ORDErr = QQ 6 of data, then this data is found as the basis, Add iN keyword search table1 compliant data based. - If the brackets are not in line with the sub-query data, then the outer query result is null.SELECT * FROM table1 WHERE QQ IN
(SELECT QQ FROM table3 WHERE ORDErr=6)


Use the keyword EXISTS subqueries

  • Example:
  • SELECT *FROM table1 WHERE EXISTS(
    SELECT QQ FROM table3 WHERE ORDErr=6)

    Features: As the grammar behind WHERE EXISTS constraint columns can not be added, so if the brackets if the value of the sub-query, then the query is outside the entire table of data.
Published 37 original articles · won praise 10 · views 10000 +

Guess you like

Origin blog.csdn.net/OneLinee/article/details/78795966
Recommended