Using union, intersect,except,union all in Sql Server
*********************************************************
Create database MySql
create database MySql
****************************************************
Create table Table1,Table2 using database MySql
use MySql
Create Table Table1 (Id int,Name nvarchar(50))
use MySql
Create Table Table2 (Id int,Name nvarchar(50))
****************************************************
Insert record both Table Table1,Table2
insert into Table1 values(1,'Kush Tiwari')
insert into Table2 values(4,'Dinesh Singh')
****************************************************
Select record both Table Table1,Table2
Select * from Table1
Select * from Table2
****************************************************
Select record both Table Table1,Table2 with union keyword
select id ,Name from Table1 union select id ,Name from Table2
****************************************************
Select record both Table Table1,Table2 with union all keyword
select id ,Name from Table1 union all select id ,Name from Table2
****************************************************
Select record both Table Table1,Table2 with intersect keyword
select id,Name from Table1 intersect select id,Name from Table2
****************************************************
Select record both Table Table1,Table2 with except keyword
select id,Name from Table1 except select id,Name from Table2
select id,Name from Table2 except select id,Name from Table1
0 comments:
Post a Comment