Understanding Combined Queries


Most SQL queries contain a single SELECT statement that returns data from one or more tables. MySQL also enables you to perform multiple queries (multiple SELECT statements) and return the results as a single query result set. These combined queries are usually known as unions or compound queries.

There are basically two scenarios in which you'd use combined queries:

  • To return similarly structured data from different tables in a single query

  • To perform multiple queries against a single table returning the data as one query

Tip

Combining Queries and Multiple WHERE Conditions For the most part, combining two queries to the same table accomplishes the same thing as a single query with multiple WHERE clause conditions. In other words, any SELECT statement with multiple WHERE clauses can also be specified as a combined query, as you'll see in the section that follows. The performance of each of the two techniques, however, can vary based on the queries used. As such, it is always good to experiment to determine which is preferable for specific queries.





MySQL Crash Course
MySQL Crash Course
ISBN: 0672327120
EAN: 2147483647
Year: 2004
Pages: 214
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net