create table books(bookid int,bookname char(1),isbn int,codeprice int,[getdate] datetime)
go
insert into books
select 1,'a',123455,12,'2009-02-06' union all
select 2,'b',125540,13,'2009-02-06' union all
select 3,'a',123455,12,'2009-02-06' union all
select 4,'d',123455,15,'2009-02-06' union all
select 5,'e',123455,16,'2009-02-06'
godelete from books
where bookid not in
(
select bookid
from books a
where not exists
(
select 1 from books
where a.isbn=isbn
and a.codeprice=codeprice
and bookid<a.bookid
)
)select * from books
其中 select 1 from books 的1代表什么
go
insert into books
select 1,'a',123455,12,'2009-02-06' union all
select 2,'b',125540,13,'2009-02-06' union all
select 3,'a',123455,12,'2009-02-06' union all
select 4,'d',123455,15,'2009-02-06' union all
select 5,'e',123455,16,'2009-02-06'
godelete from books
where bookid not in
(
select bookid
from books a
where not exists
(
select 1 from books
where a.isbn=isbn
and a.codeprice=codeprice
and bookid<a.bookid
)
)select * from books
其中 select 1 from books 的1代表什么
from books a
where not exists
(
select 1 from books
where a.isbn=isbn
and a.codeprice=codeprice
and bookid <a.bookid
)
就是一个连接子查询 ,里面可以用1 来代替!换成*也行
not exists
(
select '小梁爱兰儿' from books
where a.isbn=isbn
and a.codeprice=codeprice
and bookid <a.bookid
)------------------------------
not exists
(
select 20015254 from books
where a.isbn=isbn
and a.codeprice=codeprice
and bookid <a.bookid
)
where bookid not in
(
select bookid
from books a
where not exists
(
select 1 from books --这里的1 可以改成 2 3 等等 是任意的 这是not exists的用法 select 后面可以跟任意数字
where a.isbn=isbn
and a.codeprice=codeprice
and bookid <a.bookid
)
)
如果满足WHERE后面的条件,SELECT 1标识而已