Sign up for Hasura Newsletter
Loading...

Set Operations

MySQL supports a few Set operations which can be performed on the data in the table. These are used to create meaningful relationships between different tables or query results to combine and analyse data.

There are 3 different types of SET operations:

  • UNION
  • UNION ALL
  • MINUS

UNION

The UNION set operation is used to combine the outputs of two or more SELECT statements. This will eliminate duplicates from its result set. The number of columns and the datatype must be the same in both the tables on which the UNION operation is being used.

MySQL_56

SELECT FROM First
UNION
SELECT FROM Second;

UNION ALL

This operation is similar to Union with the only difference being that it also shows the duplicate rows.

MySQL_57

SELECT * FROM First
UNION ALL
SELECT * FROM Second;

MINUS

The Minus set operation combines the results of two SELECT statements and returns only those in the final result, which belongs to the first set of the result.

MySQL_58

SELECT * FROM First
MINUS
SELECT * FROM Second;
Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin