Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
It is generally more efficient to perform table joins rather than using multiple queries when retrieving data from multiple related tables. In the following example, two queries are used to get the product name and the product type name for product #1 (using two queries is wasteful). The first query gets the name and product_type_id column values from the products table for product #1. The second query then uses that product_type_id to get the name column from the product_types table.
-- BAD (two separate queries when one would work) SELECT name, product_type_id FROM products WHERE product_id = 1; NAME PRODUCT_TYPE_ID ------------------------------ --------------- Modern Science 1 SELECT name FROM product_types WHERE product_type_id = 1; NAME ---------- Book