Union in SQL |Union Command in SQL - sql - sql tutorial - learn sql




  • The SQL UNION clause/operator is used to combine the results of two or more SELECT statements without returning any duplicate rows.
 representation of union command in sql
  • Column data types in the two queries must match.
  • UNION combines by column position rather than column name.
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

The SQL UNION syntax

  • The general syntax is:
SELECT column-names
  FROM table-name
 UNION
SELECT column-names
  FROM table-name
SUPPLIER
Id
CompanyName
ContactName
City
Country
Phone
Fax
CUSTOMER
Id
FirstName
LastName
City
Country
Phone

Difference Between Union Unionall Except Intersect

Difference Between Union Unionall Except Intersect

SQL UNION Examples

  • Problem: List all contacts, i.e., suppliers and customers.
SELECT 'Customer' As Type, 
       FirstName + ' ' + LastName AS ContactName, 
       City, Country, Phone
  FROM Customer
UNION
SELECT 'Supplier', 
       ContactName, City, Country, Phone
  FROM Supplier
  • This is a simple example in which the table alias would be useful

Results:

Type Contact
Name
City Country Phone
Customer Alejandra
Camino
Madrid Spain (91) 745 6200
Customer Alexander
Feuer
Leipzig Germany 0342-023176
Customer Ana Trujillo México D.F. Mexico (5) 555-4729
Customer Anabela
Domingues
Sao Paulo Brazil (11) 555-2167

Union vs Union All

Union vs Union All

SQL Union Query Example

SQL Union Query Example

This tutorial provides more the basic needs and informations on sql tutorial , pl sql tutorial , mysql tutorial , sql server , sqlcode , sql queries , sql , sql formatter , sql join , w3schools sql , oracle tutorial , mysql , pl sql , learn sql , sql tutorial for beginners , sql server tutorial , sql query tutorial , oracle sql tutorial , t sql tutorial , ms sql tutorial , database tutorial , sql tutorial point , oracle pl sql tutorial , oracle database tutorial , oracle tutorial for beginners , ms sql server tutorial , sql tutorial pdf

Related Searches to Union in SQL|Union Command in SQL