Use of except in select query

Rajni.Shekhar
Posted by Rajni.Shekhar under Sql Server category on | Points: 40 | Views : 975
Select all cities from emp table except from city table.

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

Comments or Responses

Login to post response