Extract a Subset of the Results : Correlated Subquery « Query Select « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » Query Select » Correlated Subquery 
2. 37. 8. Extract a Subset of the Results
SQL>
SQL> CREATE TABLE myTable (username VARCHAR(20),score INT);

Table created.

SQL> INSERT INTO myTable VALUES ('gordon',10);

row created.

SQL> INSERT INTO myTable VALUES ('user01',20);

row created.

SQL> INSERT INTO myTable VALUES ('user02',30);

row created.

SQL> INSERT INTO myTable VALUES ('user03',40);

row created.

SQL> INSERT INTO myTable VALUES ('user04',50);

row created.

SQL> INSERT INTO myTable VALUES ('user05',60);

row created.

SQL> INSERT INTO myTable VALUES ('user06',70);

row created.

SQL> INSERT INTO myTable VALUES ('user07',80);

row created.

SQL> INSERT INTO myTable VALUES ('user08',90);

row created.

SQL> INSERT INTO myTable VALUES ('user09',100);

row created.

SQL> INSERT INTO myTable VALUES ('user10',110);

row created.

SQL> INSERT INTO myTable VALUES ('user11',120);

row created.

SQL>
SQL> SELECT username,score FROM
  2  (SELECT username,score FROM myTable ORDER BY score DESCt
  3    WHERE rownum <= 10;

USERNAME                  SCORE
-------------------- ----------
user11                      120
user10                      110
user09                      100
user08                       90
user07                       80
user06                       70
user05                       60
user04                       50
user03                       40
user02                       30

10 rows selected.

SQL> DROP TABLE myTable;

Table dropped.

SQL>
SQL>
2. 37. Correlated Subquery
2. 37. 1. Writing Correlated Subqueries
2. 37. 2. Using EXISTS and NOT EXISTS with a Correlated Subquery
2. 37. 3. A correlated subquery: the subquery references a column from a table referred to in the parent statement.
2. 37. 4. The subquery returning the literal value 1
2. 37. 5. Using NOT EXISTS with a Correlated Subquery
2. 37. 6. list all employees who is younger than Joe
2. 37. 7. List all employees who attended XML course and Java course
2. 37. 8. Extract a Subset of the Results
2. 37. 9. How Many Products By Department with correlated subqueries 1
2. 37. 10. How Many Products By Department with correlated subqueries 2
2. 37. 11. Correlated subquery using the EXISTS operator
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.