求一条sql语句,急 急 急
表#:
id household_id username name
1 8 zjh aa
2 8 zjh bb
3 8 zjh cc
4 9 xl dd
5 9 xl ee
6 9 xl ff
表#1:
id household_id username name
1 8 zjh aa
2 8 zjh bb
要求得到的结果为:
id household_id username name
3 8 zjh cc
要求:在表#中选择出与表#1中username,household_id 相同 ,id 不同的数据!
create table #( id int identity,household_id int ,username varchar(10),name varchar(10))
insert into #(household_id,username,name) select '8 ', 'zjh ', 'aa '
insert into #(household_id,username,name) select '8 ', 'zjh ', 'bb '
insert into #(household_id,username,name) select '8 ', 'zjh ', 'cc '
insert into #(household_id,username,name) select '9 ', 'xl ', 'dd '
insert into #(household_id,username,name) select '9 ', 'xl ', 'ee '
insert into #(household_id,u