What is the difference between select distinct and union in SQL?

Query By: CHRIS KEEGAN

H

HEMA REDDY

SELECT DISTINCT In SQL

  • SQL SELECT DISTINCT Statement is used to returns only different values in a table.
  • SELECT DISTINCT Clause eliminates duplicate records from the results records.

SELECT DISTINCT Syntax in SQL

SELECT DISTINCT column_1, column_2, column_3, ...

FROM table_name;


UNION In SQL

  • The SQL UNION is an operator, it is used to combine the results of two or more SELECT query statements.
  • The good thing SQL UNION, it removes the duplicate row between both SELECT statements.
  • When combining two tables with the UNION operator need to make sure the datatypes and number of fields in the result sets are similar otherwise it gives an error.

UNION Operator Syntax in SQL

SELECT column_1, column_2, column_3, ...

FROM table_name_1 UNION

SELECT column_1, column_2, column_3, ...

FROM table_name_2;

0 votes

Your Answer

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

LifeStyle & Fun

© 2024 GDATAMART.COM (All Rights Reserved)