ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
SQL UNION

Reference :-


       http://www.w3resource.com/sql/sql-union.php



       http://dev.mysql.com/doc/refman/5.0/en/union.html
SQL UNION


Description:-


The SQL UNION operator combines the results of two or more queries and makes a
result set which includes fetched rows from the participating queries in the UNION.
Basic rules for combining two or more queries using UNION :
1.) number of columns and order of columns of all queries must be same.
2.) the data types of the columns on involving table in each query must be same or
compatible.
3.) Usually returned column names are taken from the first query.
By default the UNION behalves like UNION [DISTINCT] , i.e. eliminated the duplicate
rows; however, using ALL keyword with UNION returns all rows, including duplicates.
SQL UNION

Example of SQL UNION


Code:-

         SELECT prod_code,prod_name

         FROM product

         UNION

         SELECT prod_code,prod_name

         FROM purchase;
SQL UNION ALL

Example of SQL UNION ALL


Code:-

         SELECT prod_code,prod_name,com_name

         FROM product

         UNION ALL

         SELECT prod_code,prod_name,com_name

         FROM purchase;
SQL UNION ALL

Explanation



 In the above example the optional clause ALL have been added with UNION for which,
 all the rows from each query have been available in the result set. Here in the above
 output the marking rows are non-unique but it has been displayed. If ignored ALL
 clause, the marking rows would have come once.
Sql UNION ALL using where

   Example of Sql UNION ALL using where

Code:-
           SELECT prod_code,prod_name,com_name

           FROM product

           WHERE life>6

           UNION ALL

           SELECT prod_code,prod_name,com_name

           FROM purchase

           WHERE pur_qty>10
Sql UNION ALL using where


Explanation:-



 In the above example the two queries have been set using two different criterias
 including WHERE clause. So all the retrieve rows (including duplicates) have displayed
 in the result set. Here in this example the marking rows are identical, but it has been
 displayed for the ALL clause along with UNION. If ignored ALL clause the marking rows
 would have come once.
Sql UNION a table to itself

    Example of Sql UNION a table to itself

Code:-
           SELECT prod_code,prod_name,com_name

           FROM purchase

           WHERE pur_qty>6

           UNION ALL

           SELECT prod_code,prod_name,com_name

           FROM purchase

           WHERE pur_amount>100000
Sql UNION a table to itself


Explanation:-

 In the above example the two queries have been set using two different criterias for a
 same table. So all the retrieved rows ( including duplicates ) have displayed. Here in
 this example the marking rows are identical, but it has been displayed for the ALL
 clause along with UNION.
Sql UNION with different column names

     Example of Sql UNION a table to itself

 Code:-
          SELECT prod_code,prod_name,life

          FROM product

          WHERE life>6

          UNION

          SELECT prod_code,prod_name,pur_qty

          FROM purchase

          WHERE pur_qty<20
Sql UNION with different column names


Explanation:-



 n the above example the two queries have been set using two different criterias and
 different columns. The different columns in two statements are 'life' and 'pur_qty'. But
 as the data type are same for both the columns so, result have displayed. Usually
 returned column names are taken from the first query.
Sql UNION with Inner Join
         Example of Sql UNION a table to itself
          SELECT product.prod_code,product.prod_name,
Code:-
          purchase.pur_qty, purchase.pur_amount

          FROM product

          INNER JOIN purchase

          ON product.prod_code =purchase.prod_code

          UNION

          SELECT product.prod_code,product.prod_name,

          purchase.pur_qty, purchase.pur_amount

          FROM product

          INNER JOIN purchase

          ON product.prod_name =purchase.prod_name;
Sql UNION with Inner Join


Explanation:-



 n the above example the union made by two queries. The queries are two inner join
 statement. In the first query the join take place between two tables where the
 prod_code of both tables are same and in the 2nd query the join take place between
 two tables where the prod_name of both tables are same.

More Related Content

What's hot (20)

Computer Science:Sql Set Operation
Computer Science:Sql Set OperationComputer Science:Sql Set Operation
Computer Science:Sql Set Operation
St Mary's College,Thrissur,Kerala
?
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
?
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
Lakshman Basnet
?
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
Syed Hassan Ali
?
Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
?
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
Wings Interactive
?
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
Deepthi Rachumallu
?
Plsql lab mannual
Plsql lab mannualPlsql lab mannual
Plsql lab mannual
Harish Khodke
?
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause
Deepam Aggarwal
?
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
ammarbrohi
?
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
Syed Zaid Irshad
?
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
rainynovember12
?
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
Naimul Arif
?
SQL
SQLSQL
SQL
Shyam Khant
?
Set operators
Set  operatorsSet  operators
Set operators
Manuel S. Enverga University Foundation
?
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
Dhananjay Goel
?
DML Commands
DML CommandsDML Commands
DML Commands
Randy Riness @ South Puget Sound Community College
?
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
?
Create table
Create tableCreate table
Create table
Nitesh Singh
?
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
?

Similar to SQL UNION (20)

Sql ch 5
Sql ch 5Sql ch 5
Sql ch 5
Mukesh Tekwani
?
Sql clauses by Manan Pasricha
Sql clauses by Manan PasrichaSql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
MananPasricha
?
Sql Tuning
Sql TuningSql Tuning
Sql Tuning
MuhammadAbdulRehmanQ
?
Sql wksht-6
Sql wksht-6Sql wksht-6
Sql wksht-6
Mukesh Tekwani
?
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
KV(AFS) Utarlai, Barmer (Rajasthan)
?
Sql
SqlSql
Sql
Aman Lalpuria
?
Sql joins
Sql joinsSql joins
Sql joins
Vivek Singh
?
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxUnit 3-Select Options and Aggregate Functions in SQL (1).pptx
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
HAMEEDHUSSAINBU21CSE
?
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
?
Unit 3-p2relationaldatabasescodeing.pptx
Unit 3-p2relationaldatabasescodeing.pptxUnit 3-p2relationaldatabasescodeing.pptx
Unit 3-p2relationaldatabasescodeing.pptx
artipunia12
?
Les07[1]Multiple-Column Subqueries
Les07[1]Multiple-Column SubqueriesLes07[1]Multiple-Column Subqueries
Les07[1]Multiple-Column Subqueries
siavosh kaviani
?
advanced sql(database)
advanced sql(database)advanced sql(database)
advanced sql(database)
welcometofacebook
?
OER UNIT 5 SQL MODEL CLAUSE
OER UNIT 5 SQL MODEL CLAUSEOER UNIT 5 SQL MODEL CLAUSE
OER UNIT 5 SQL MODEL CLAUSE
Girija Muscut
?
1 z0 047
1 z0 0471 z0 047
1 z0 047
Md. Shamsul haque
?
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
DataminingTools Inc
?
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
oracle content
?
The Database Environment Chapter 8
The Database Environment Chapter 8The Database Environment Chapter 8
The Database Environment Chapter 8
Jeanie Arnoco
?
235689260 oracle-forms-10g-tutorial
235689260 oracle-forms-10g-tutorial235689260 oracle-forms-10g-tutorial
235689260 oracle-forms-10g-tutorial
homeworkping3
?
5. Group Functions
5. Group Functions5. Group Functions
5. Group Functions
Evelyn Oluchukwu
?
ADV PPT 8 LAB.pptx
ADV PPT 8 LAB.pptxADV PPT 8 LAB.pptx
ADV PPT 8 LAB.pptx
ArjayBalberan1
?

Recently uploaded (20)

Cisco Duo 2024 Cisco Duo 2024 Cisco Duo 2024
Cisco Duo 2024 Cisco Duo 2024 Cisco Duo 2024Cisco Duo 2024 Cisco Duo 2024 Cisco Duo 2024
Cisco Duo 2024 Cisco Duo 2024 Cisco Duo 2024
MichaelLee15927
?
UiPath Automation Developer Associate Training Series 2025 - Session 4
UiPath Automation Developer Associate Training Series 2025 - Session 4UiPath Automation Developer Associate Training Series 2025 - Session 4
UiPath Automation Developer Associate Training Series 2025 - Session 4
DianaGray10
?
Unlock AI Creativity: Image Generation with DALL¡¤E
Unlock AI Creativity: Image Generation with DALL¡¤EUnlock AI Creativity: Image Generation with DALL¡¤E
Unlock AI Creativity: Image Generation with DALL¡¤E
Expeed Software
?
Automated Minutes - Redefining Capturing & Creating Minutes
Automated Minutes - Redefining Capturing & Creating MinutesAutomated Minutes - Redefining Capturing & Creating Minutes
Automated Minutes - Redefining Capturing & Creating Minutes
OnBoard
?
Read- and Write-Optimization in Modern Database Infrastructures by Dzejla Med...
Read- and Write-Optimization in Modern Database Infrastructures by Dzejla Med...Read- and Write-Optimization in Modern Database Infrastructures by Dzejla Med...
Read- and Write-Optimization in Modern Database Infrastructures by Dzejla Med...
ScyllaDB
?
Gmetrics: Processing Metrics at Uber Scale by Cristian Velazquez
Gmetrics: Processing Metrics at Uber Scale by Cristian VelazquezGmetrics: Processing Metrics at Uber Scale by Cristian Velazquez
Gmetrics: Processing Metrics at Uber Scale by Cristian Velazquez
ScyllaDB
?
People, Process, Technology, Business...
People, Process, Technology, Business...People, Process, Technology, Business...
People, Process, Technology, Business...
annashipman
?
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOTSMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
TanmaiArni
?
Verbose AI: The Accessibility Challenge - CSUN 2025
Verbose AI: The Accessibility Challenge - CSUN 2025Verbose AI: The Accessibility Challenge - CSUN 2025
Verbose AI: The Accessibility Challenge - CSUN 2025
Ted Drake
?
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (ƽɽÒã)
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (ƽɽÒã)DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (ƽɽÒã)
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (ƽɽÒã)
Tsuyoshi Hirayama
?
ScyllaDB is No Longer "Just a Faster Cassandra" by Felipe Cardeneti Mendes
ScyllaDB is No Longer "Just a Faster Cassandra" by Felipe Cardeneti MendesScyllaDB is No Longer "Just a Faster Cassandra" by Felipe Cardeneti Mendes
ScyllaDB is No Longer "Just a Faster Cassandra" by Felipe Cardeneti Mendes
ScyllaDB
?
Who Needs One Database Anyway? byGlauber Costa
Who Needs One Database Anyway? byGlauber CostaWho Needs One Database Anyway? byGlauber Costa
Who Needs One Database Anyway? byGlauber Costa
ScyllaDB
?
Extreme Elasticity with Tablets, Raft and Kubernetes by Maciej Zimnoch
Extreme Elasticity with Tablets, Raft and Kubernetes by Maciej ZimnochExtreme Elasticity with Tablets, Raft and Kubernetes by Maciej Zimnoch
Extreme Elasticity with Tablets, Raft and Kubernetes by Maciej Zimnoch
ScyllaDB
?
The Mechanics of Scale by Dominik Tornow
The Mechanics of Scale by Dominik TornowThe Mechanics of Scale by Dominik Tornow
The Mechanics of Scale by Dominik Tornow
ScyllaDB
?
Raport-trendy-technologia-FTSG_2025_TR_FINAL_LINKED
Raport-trendy-technologia-FTSG_2025_TR_FINAL_LINKEDRaport-trendy-technologia-FTSG_2025_TR_FINAL_LINKED
Raport-trendy-technologia-FTSG_2025_TR_FINAL_LINKED
agatadrynko
?
How Agoda Scaled 50x Throughput with ScyllaDB by Worakarn Isaratham
How Agoda Scaled 50x Throughput with ScyllaDB by Worakarn IsarathamHow Agoda Scaled 50x Throughput with ScyllaDB by Worakarn Isaratham
How Agoda Scaled 50x Throughput with ScyllaDB by Worakarn Isaratham
ScyllaDB
?
ScyllaDB: 10 Years and Beyond by Dor Laor
ScyllaDB: 10 Years and Beyond by Dor LaorScyllaDB: 10 Years and Beyond by Dor Laor
ScyllaDB: 10 Years and Beyond by Dor Laor
ScyllaDB
?
Bridging the Gap from Telco to Techco with Agile Architecture
Bridging the Gap from Telco to Techco with Agile ArchitectureBridging the Gap from Telco to Techco with Agile Architecture
Bridging the Gap from Telco to Techco with Agile Architecture
BATbern
?
TrustArc Webinar: How to Create a Privacy-First Culture
TrustArc Webinar: How to Create a Privacy-First CultureTrustArc Webinar: How to Create a Privacy-First Culture
TrustArc Webinar: How to Create a Privacy-First Culture
TrustArc
?
CFD Studio Credentials ¨C Branding, Design & Development
CFD Studio Credentials ¨C Branding, Design & DevelopmentCFD Studio Credentials ¨C Branding, Design & Development
CFD Studio Credentials ¨C Branding, Design & Development
trannghia2018
?
Cisco Duo 2024 Cisco Duo 2024 Cisco Duo 2024
Cisco Duo 2024 Cisco Duo 2024 Cisco Duo 2024Cisco Duo 2024 Cisco Duo 2024 Cisco Duo 2024
Cisco Duo 2024 Cisco Duo 2024 Cisco Duo 2024
MichaelLee15927
?
UiPath Automation Developer Associate Training Series 2025 - Session 4
UiPath Automation Developer Associate Training Series 2025 - Session 4UiPath Automation Developer Associate Training Series 2025 - Session 4
UiPath Automation Developer Associate Training Series 2025 - Session 4
DianaGray10
?
Unlock AI Creativity: Image Generation with DALL¡¤E
Unlock AI Creativity: Image Generation with DALL¡¤EUnlock AI Creativity: Image Generation with DALL¡¤E
Unlock AI Creativity: Image Generation with DALL¡¤E
Expeed Software
?
Automated Minutes - Redefining Capturing & Creating Minutes
Automated Minutes - Redefining Capturing & Creating MinutesAutomated Minutes - Redefining Capturing & Creating Minutes
Automated Minutes - Redefining Capturing & Creating Minutes
OnBoard
?
Read- and Write-Optimization in Modern Database Infrastructures by Dzejla Med...
Read- and Write-Optimization in Modern Database Infrastructures by Dzejla Med...Read- and Write-Optimization in Modern Database Infrastructures by Dzejla Med...
Read- and Write-Optimization in Modern Database Infrastructures by Dzejla Med...
ScyllaDB
?
Gmetrics: Processing Metrics at Uber Scale by Cristian Velazquez
Gmetrics: Processing Metrics at Uber Scale by Cristian VelazquezGmetrics: Processing Metrics at Uber Scale by Cristian Velazquez
Gmetrics: Processing Metrics at Uber Scale by Cristian Velazquez
ScyllaDB
?
People, Process, Technology, Business...
People, Process, Technology, Business...People, Process, Technology, Business...
People, Process, Technology, Business...
annashipman
?
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOTSMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
SMART SENTRY CYBER THREAT INTELLIGENCE IN IIOT
TanmaiArni
?
Verbose AI: The Accessibility Challenge - CSUN 2025
Verbose AI: The Accessibility Challenge - CSUN 2025Verbose AI: The Accessibility Challenge - CSUN 2025
Verbose AI: The Accessibility Challenge - CSUN 2025
Ted Drake
?
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (ƽɽÒã)
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (ƽɽÒã)DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (ƽɽÒã)
DAO UTokyo 2025 DLT mass adoption case studies IBM Tsuyoshi Hirayama (ƽɽÒã)
Tsuyoshi Hirayama
?
ScyllaDB is No Longer "Just a Faster Cassandra" by Felipe Cardeneti Mendes
ScyllaDB is No Longer "Just a Faster Cassandra" by Felipe Cardeneti MendesScyllaDB is No Longer "Just a Faster Cassandra" by Felipe Cardeneti Mendes
ScyllaDB is No Longer "Just a Faster Cassandra" by Felipe Cardeneti Mendes
ScyllaDB
?
Who Needs One Database Anyway? byGlauber Costa
Who Needs One Database Anyway? byGlauber CostaWho Needs One Database Anyway? byGlauber Costa
Who Needs One Database Anyway? byGlauber Costa
ScyllaDB
?
Extreme Elasticity with Tablets, Raft and Kubernetes by Maciej Zimnoch
Extreme Elasticity with Tablets, Raft and Kubernetes by Maciej ZimnochExtreme Elasticity with Tablets, Raft and Kubernetes by Maciej Zimnoch
Extreme Elasticity with Tablets, Raft and Kubernetes by Maciej Zimnoch
ScyllaDB
?
The Mechanics of Scale by Dominik Tornow
The Mechanics of Scale by Dominik TornowThe Mechanics of Scale by Dominik Tornow
The Mechanics of Scale by Dominik Tornow
ScyllaDB
?
Raport-trendy-technologia-FTSG_2025_TR_FINAL_LINKED
Raport-trendy-technologia-FTSG_2025_TR_FINAL_LINKEDRaport-trendy-technologia-FTSG_2025_TR_FINAL_LINKED
Raport-trendy-technologia-FTSG_2025_TR_FINAL_LINKED
agatadrynko
?
How Agoda Scaled 50x Throughput with ScyllaDB by Worakarn Isaratham
How Agoda Scaled 50x Throughput with ScyllaDB by Worakarn IsarathamHow Agoda Scaled 50x Throughput with ScyllaDB by Worakarn Isaratham
How Agoda Scaled 50x Throughput with ScyllaDB by Worakarn Isaratham
ScyllaDB
?
ScyllaDB: 10 Years and Beyond by Dor Laor
ScyllaDB: 10 Years and Beyond by Dor LaorScyllaDB: 10 Years and Beyond by Dor Laor
ScyllaDB: 10 Years and Beyond by Dor Laor
ScyllaDB
?
Bridging the Gap from Telco to Techco with Agile Architecture
Bridging the Gap from Telco to Techco with Agile ArchitectureBridging the Gap from Telco to Techco with Agile Architecture
Bridging the Gap from Telco to Techco with Agile Architecture
BATbern
?
TrustArc Webinar: How to Create a Privacy-First Culture
TrustArc Webinar: How to Create a Privacy-First CultureTrustArc Webinar: How to Create a Privacy-First Culture
TrustArc Webinar: How to Create a Privacy-First Culture
TrustArc
?
CFD Studio Credentials ¨C Branding, Design & Development
CFD Studio Credentials ¨C Branding, Design & DevelopmentCFD Studio Credentials ¨C Branding, Design & Development
CFD Studio Credentials ¨C Branding, Design & Development
trannghia2018
?

SQL UNION

  • 1. SQL UNION Reference :- http://www.w3resource.com/sql/sql-union.php http://dev.mysql.com/doc/refman/5.0/en/union.html
  • 2. SQL UNION Description:- The SQL UNION operator combines the results of two or more queries and makes a result set which includes fetched rows from the participating queries in the UNION. Basic rules for combining two or more queries using UNION : 1.) number of columns and order of columns of all queries must be same. 2.) the data types of the columns on involving table in each query must be same or compatible. 3.) Usually returned column names are taken from the first query. By default the UNION behalves like UNION [DISTINCT] , i.e. eliminated the duplicate rows; however, using ALL keyword with UNION returns all rows, including duplicates.
  • 3. SQL UNION Example of SQL UNION Code:- SELECT prod_code,prod_name FROM product UNION SELECT prod_code,prod_name FROM purchase;
  • 4. SQL UNION ALL Example of SQL UNION ALL Code:- SELECT prod_code,prod_name,com_name FROM product UNION ALL SELECT prod_code,prod_name,com_name FROM purchase;
  • 5. SQL UNION ALL Explanation In the above example the optional clause ALL have been added with UNION for which, all the rows from each query have been available in the result set. Here in the above output the marking rows are non-unique but it has been displayed. If ignored ALL clause, the marking rows would have come once.
  • 6. Sql UNION ALL using where Example of Sql UNION ALL using where Code:- SELECT prod_code,prod_name,com_name FROM product WHERE life>6 UNION ALL SELECT prod_code,prod_name,com_name FROM purchase WHERE pur_qty>10
  • 7. Sql UNION ALL using where Explanation:- In the above example the two queries have been set using two different criterias including WHERE clause. So all the retrieve rows (including duplicates) have displayed in the result set. Here in this example the marking rows are identical, but it has been displayed for the ALL clause along with UNION. If ignored ALL clause the marking rows would have come once.
  • 8. Sql UNION a table to itself Example of Sql UNION a table to itself Code:- SELECT prod_code,prod_name,com_name FROM purchase WHERE pur_qty>6 UNION ALL SELECT prod_code,prod_name,com_name FROM purchase WHERE pur_amount>100000
  • 9. Sql UNION a table to itself Explanation:- In the above example the two queries have been set using two different criterias for a same table. So all the retrieved rows ( including duplicates ) have displayed. Here in this example the marking rows are identical, but it has been displayed for the ALL clause along with UNION.
  • 10. Sql UNION with different column names Example of Sql UNION a table to itself Code:- SELECT prod_code,prod_name,life FROM product WHERE life>6 UNION SELECT prod_code,prod_name,pur_qty FROM purchase WHERE pur_qty<20
  • 11. Sql UNION with different column names Explanation:- n the above example the two queries have been set using two different criterias and different columns. The different columns in two statements are 'life' and 'pur_qty'. But as the data type are same for both the columns so, result have displayed. Usually returned column names are taken from the first query.
  • 12. Sql UNION with Inner Join Example of Sql UNION a table to itself SELECT product.prod_code,product.prod_name, Code:- purchase.pur_qty, purchase.pur_amount FROM product INNER JOIN purchase ON product.prod_code =purchase.prod_code UNION SELECT product.prod_code,product.prod_name, purchase.pur_qty, purchase.pur_amount FROM product INNER JOIN purchase ON product.prod_name =purchase.prod_name;
  • 13. Sql UNION with Inner Join Explanation:- n the above example the union made by two queries. The queries are two inner join statement. In the first query the join take place between two tables where the prod_code of both tables are same and in the 2nd query the join take place between two tables where the prod_name of both tables are same.