PostgreSQL union | PostgreSQL union all | PostgreSQL intersect

  • Post comments:0 Comments
  • Reading time:4 mins read
  • Post category:SQL

PostgreSQL: using Set Operators: Postgresql UNION

Set operators combine the results of two component queries into a single result. Queries containing set operators are called compound queries. set operators include PostgreSQL union, PostgreSQL intersect etc.,

There are four types of set operators, they are

Operator                      Returns

UNION                         Distinct rows selected by either query

UNION ALL                All rows selected by either query, including all duplicates

INTERSECT               All distinct rows selected by both queries

EXCEPT                     All distinct rows selected by the first query but not the second

Lets understand the above set operators using examples.

PostgreSQL UNION Clause

Syntax

select statement_1 union select statement_2;

PostgreSQL UNION ALL Clause

Syntax

select statement_1 union all select statement_2;

PostgreSQL INTERSECT Clause

Syntax

select statement_1 intersect select statement_2;

PostgreSQL EXCEPTClause

Syntax

select statement_1 exceptselect statement_2;

Words from postgreshelp

Thank you for giving your valuable time to read the above information. I hope the content served your purpose in reaching out the blog.
Suggestions for improvement of the blog are highly appreciable. Please contact us for any information/suggestion/feedback.

If you want to be updated with all our articles

please follow us on Facebook Twitter
Please subscribe to our newsletter.

Leave a Reply