In and subquery : Subquery IN « Subquery « Oracle PL / SQL

Home
Oracle PL / SQL
1.Aggregate Functions
2.Analytical Functions
3.Char Functions
4.Constraints
5.Conversion Functions
6.Cursor
7.Data Type
8.Date Timezone
9.Hierarchical Query
10.Index
11.Insert Delete Update
12.Large Objects
13.Numeric Math Functions
14.Object Oriented Database
15.PL SQL
16.Regular Expressions
17.Report Column Page
18.Result Set
19.Select Query
20.Sequence
21.SQL Plus
22.Stored Procedure Function
23.Subquery
24.System Packages
25.System Tables Views
26.Table
27.Table Joins
28.Trigger
29.User Previliege
30.View
31.XML
Oracle PL / SQL » Subquery » Subquery IN 
In and subquery
  

SQL> create table courses
  2  code        VARCHAR2(6)  constraint C_PK
  3                             primary key
  4  , description VARCHAR2(30)
  5  , category    CHAR(3)
  6  , duration    NUMBER(2)
  7  ;

Table created.

SQL> insert into courses values('SQL','SQL','GEN',4);

row created.

SQL> insert into courses values('OAU','Java','GEN',1);

row created.

SQL> insert into courses values('JAV','C++','BLD',4);

row created.

SQL> insert into courses values('PLS','C','BLD',1);

row created.

SQL> insert into courses values('XML','XML','BLD',2);

row created.

SQL> insert into courses values('ERM','ERP','DSG',3);

row created.

SQL> insert into courses values('PMT','ERP','DSG',1);

row created.

SQL> insert into courses values('RSD','jQuery','DSG',2);

row created.

SQL> insert into courses values('PRO','Linux','DSG',5);

row created.

SQL> insert into courses values('GEN','Oracle','DSG',4);

row created.

SQL>
SQL> create table registrations
  2  attendee    NUMBER(4)
  3  , course      VARCHAR2(6)
  4  , begindate   DATE
  5  , evaluation  NUMBER(1)
  6  , constraint  R_PK        primary key (attendee,course,begindate)
  7  ;

Table created.

SQL>
SQL> insert into registrations values (2,'SQL',date '2009-04-12',4   );

row created.

SQL> insert into registrations values (14,'SQL',date '2009-04-12',5   );

row created.

SQL> insert into registrations values (6,'SQL',date '2009-04-12',4   );

row created.

SQL> insert into registrations values (11,'SQL',date '2009-04-12',2   );

row created.

SQL> insert into registrations values (8,'SQL',date '2009-10-04',NULL);

row created.

SQL> insert into registrations values (9,'SQL',date '2009-10-04',3   );

row created.

SQL> insert into registrations values (13,'SQL',date '2009-10-04',4   );

row created.

SQL> insert into registrations values (13,'SQL',date '2009-12-13',NULL);

row created.

SQL> insert into registrations values (6,'SQL',date '2009-12-13',NULL);

row created.

SQL> insert into registrations values (3,'OAU',date '2009-08-10',4   );

row created.

SQL>
SQL> select attendee
  2  from   registrations
  3  where  course in (select code
  4                    from   courses
  5                    where  category = 'BLD');

no rows selected

SQL> select attendee
  2  from   registrations
  3  where  evaluation in (select duration
  4                        from   courses
  5                        where  category = 'BLD');

  ATTENDEE
----------
        11
         2
         6
         3
        13

SQL> drop table registrations;

Table dropped.

SQL> drop table courses;

Table dropped.

   
    
  
Related examples in the same category
1.Multiple Row Subqueries: IN with subquery
2.Multiple Row Subqueries: NOT IN with subquery
3.Not in and subquery
4.in subquery
5.All locations, where courses are offering, have no departments (subquery)
6.Multiple-row subqueries return more than one row of result from the subquery
7.Selecting Products That Belong to Department with Subquery
8.Subquery in from clause
9.Using Set Membership with Subqueries
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.