This section takes you through some example syntax for advanced query techniques in MySQL. For more details on this syntax, visit Chapter 11, Advanced Query Techniques. This chapter will also outline the differences in syntax for Oracle, PostgreSQL, and SQL Server.
Advanced query techniques
Syntax for subqueries
In the following code, the query inside parentheses is the inner query, while the query outside parentheses is the outer query.
To use a subquery, you can follow the following sample syntax:
SELECT col1
FROM table1
WHERE col1 IN
(SELECT col1 FROM table 2 WHERE col1 = 'test')
For a non-correlated subquery in WHERE with multiple values being returned, you can follow the following sample syntax. The square...