Exists

Use a subquery to test for the existence of rows.

Syntax
      EXISTS subquery

      NOT EXISTS subquery

Key
   subquery  A restricted SELECT statement.
             (The COMPUTE clause and the INTO keyword are not allowed.)

Examples

IF EXISTS (select *
from sales
where customer_id = 123)
Print 'Record exits'
ELSE
Print 'Record doesn''t exist' SELECT sal.sales_id
FROM Sales AS sal
WHERE NOT EXISTS
(SELECT *
FROM Discounts AS disc
WHERE sal.sales_id = disc.sales_id );

“If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim...” ~ Rudyard Kipling 1899

Related:

IF
Equivalent Oracle command: Select into a cursor then: IF SQL%FOUND THEN...


© Copyright SS64.com 1999-2014
Some rights reserved