Skip to content

Commit a4f47d3

Browse files
sql
1 parent c63d66a commit a4f47d3

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

SELECT CLAUSE 2/EXISTS Operator.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- The SQL EXISTS operator tests the existence of any value in a subquery
2+
-- i.e. it executes the outer SQL query only if the subquery is not NULL (empty result-set).
3+
4+
-- Syntax:
5+
/*
6+
SELECT column1, column2, ...
7+
FROM table_name
8+
WHERE EXISTS (subquery);
9+
*/
10+
11+
-- Example: select all customers from the customers table who have placed an order
12+
13+
SELECT id, name
14+
FROM customers
15+
WHERE EXISTS(SELECT order_id
16+
FROM order_details
17+
WHERE customers.id = order_details.customer_id);
18+
19+
-- Example: -- select customer id , name AND country of customers whose order amount is less than 12000
20+
21+
SELECT id, name, country
22+
FROM customers
23+
WHERE EXISTS(SELECT order_id
24+
FROM order_details
25+
WHERE customers.id = order_details.customer_id
26+
AND price < 12000);

SELECT CLAUSE 2/NOT EXISTS.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- We can also use the NOT operator to inverse the working of the EXISTS clause.
2+
-- The SQL command executes if the subquery returns an empty result-set.
3+
4+
-- -- Example: select all customers from the customers table who have not placed an order
5+
6+
SELECT id, name
7+
FROM customers
8+
WHERE NOT EXISTS(SELECT order_id
9+
FROM order_details
10+
WHERE customers.id = order_details.customer_id);

SQL JOINS/SQL JOINS.sql

Whitespace-only changes.

SQL.session.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
select *,
2-
case
3-
when age > any (select age from teachers) then 'Declined'
4-
else 'Approved'
5-
end as Status
6-
from students;

0 commit comments

Comments
 (0)