How To Use Subqueries in the FROM clause?
Page 1 of 1
How To Use Subqueries in the FROM clause?
If you have a query returning many rows of data, and you want to perform another query on those
rows, you can put the first query as a subquery in the FROM clause of the second query. The
following statement shows you how to use a subquery as base table for the main query:
SQL> SELECT * FROM (
SELECT first_name, last_name, department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id
) WHERE department_name LIKE 'S%' ORDER BY last_name;
FIRST_NAME LAST_NAME DEPARTMENT_NAME
-------------------- ------------------------- --------------------
Ellen Abel Sales
Sundar Ande Sales
Mozhe Atkinson Shipping
Amit Banda Sales
Elizabeth Bates Sales
Sarah Bell Shipping
rows, you can put the first query as a subquery in the FROM clause of the second query. The
following statement shows you how to use a subquery as base table for the main query:
SQL> SELECT * FROM (
SELECT first_name, last_name, department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id
) WHERE department_name LIKE 'S%' ORDER BY last_name;
FIRST_NAME LAST_NAME DEPARTMENT_NAME
-------------------- ------------------------- --------------------
Ellen Abel Sales
Sundar Ande Sales
Mozhe Atkinson Shipping
Amit Banda Sales
Elizabeth Bates Sales
Sarah Bell Shipping
Similar topics
» How To Count Groups Returned with the GROUP BY Clause?
» How To Use Subqueries with the IN Operator?
» How To Use Subqueries with the EXISTS Operator?
» How To Write an Inner Join with the WHERE Clause?
» Can Group Functions Be Used in the ORDER BY Clause?
» How To Use Subqueries with the IN Operator?
» How To Use Subqueries with the EXISTS Operator?
» How To Write an Inner Join with the WHERE Clause?
» Can Group Functions Be Used in the ORDER BY Clause?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal