Monday, May 21, 2012

except keyword in sql server

CREATE TABLE EMP  (ID INTEGER NOT NULL,NAME VARCHAR(20) NOT NULL, CITY   VARCHAR(20) NULL)                    
                       

insert into EMP values(1,  'EMP1', 'DELHI')
insert into EMP values(2,  'EMP2', 'CHENNAI')
insert into EMP values(3,  'EMP3', 'PUNE')
insert into EMP values(4,  'EMP4', 'AGRA')
insert into EMP values(5,  'EMP5', 'CHENNAI')

CREATE TABLE CITY(ID INT IDENTITY, CITY_NAME VARCHAR(20))

insert into CITY values('CHENNAI')
SELECT CITY FROM EMP EXCEPT SELECT CITY_NAME FROM CITY

No comments:

Post a Comment