you can try creating a view
CREATE VIEW myview
AS
SELECT col1,col2, col3
FROM yourtable
WHERE col1 = 'value'
Then query the results of the view
Subquery: Simple Example
Let's say we need to provide a list of all of our customers that have placed orders for more than $1000. We don't need the order information, just the customer information. We could accomplish this with a subquery as follows:
SELECT *
FROM customer
WHERE CustNo IN (SELECT CustNo
FROM orders
WHERE ItemsTotal > 1000)
The subquery is the portion enclosed in parentheses. The above expression tells Local SQL to execute the subquery first, which forms a list of customer numbers for all orders greater than $1000. The other query uses this result as the criteria list for the IN function. In this case, the same result could've been accomplished with an INNER JOIN and a SELECT DISTINCT. We were illustrating a simple example - not all subqueries are so trivial.
|