Using Subqueries In MySQL (part 2) (
Page 1 of 9 )
In this concluding segment of our MySQL subquery tutorial, find out how to do more with subqueries, including check for matching values with the IN operator, check for valid result sets with the EXISTS operator, derive new "virtual" tables for use in the FROM clause of outer queries, and UPDATE and DELETE records selectively.In the first part of this article, I introduced you to subqueries, one of the
most powerful and useful new features in MySQL 4.1, and showed you how you can
use them to filter SQL result sets. I demonstrated how subqueries can be used in
both the WHERE and HAVING clause of outer SELECT queries, in combination with
MySQL's other comparison and logical operators, with MySQL's aggregate functions
and with the GROUP BY clause.
However, that's just the tip of the iceberg. In the concluding segment of
this tutorial, I'm going to delve into the more advanced aspects of subqueries,
showing you how to use them within a SELECT's query's FROM clause, with the IN
operator and the EXISTS test, and in UPDATE and DELETE queries. Let's get
going!