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 commands

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


 
Copyright © 1999-2024 SS64.com
Some rights reserved