🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to PostgreSQL Notes
Topic #39

PostgreSQL EXISTS


EXISTS

The EXISTS operator is used to test for the existence of any record in a sub query.

The EXISTS operator returns TRUE if the sub query returns one or more records.

Example

SELECT customers.customer_name
FROM customers
WHERE EXISTS (

SELECT order_id

FROM orders
  WHERE customer_id = customers.customer_id
);

The result in example above showed that 89 customers had at least one order in the orders table.


NOT EXISTS

To check which customers that do not have any orders, we can use the NOT operator together with the EXISTS operator :

Example

SELECT customers.customer_name
FROM customers
WHERE NOT EXISTS (

SELECT order_id

FROM orders
  WHERE customer_id = customers.customer_id
);

Want to go beyond the notes?

Join CodingNow 2.0's PostgreSQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

PostgreSQL EXISTS – FAQs

Quick answers about learning PostgreSQL EXISTS in PostgreSQL.

This free note from CodingNow 2.0 explains PostgreSQL EXISTS in PostgreSQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every PostgreSQL topic on CodingNow 2.0, including PostgreSQL EXISTS, is 100% free with no signup required.
With focused practice, most students grasp PostgreSQL EXISTS in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now