有两个表:
create table author (id int primary key auto_increment, name varchar(255));
insert into author (name) values ('tingwei');
insert into author (name) values ('jiahui');
insert into author (name) values ('naidan');
insert into author (name) values ('weizhi');
insert into author (name) values ('siyao');
create table book (author_id int primary key auto_increment, book varchar(255));
insert into book (book) values ('I love you');
insert into book (book) values ('I hate you');
insert into book (book) values ('I miss you');
但是我不知道通过在“选择”后面使用数字1表示此语句是什么意思:
select *
from author
where exists (select 1 from book where book.author_id = author.id)
我已经在线搜索了一些信息,但一无所获。
SELECT 1
就是这样:选择值1
。与WHERE EXISTS
一起使用时,子查询返回什么数据都没有关系,只要它返回任何数据即可(换句话说:返回至少一行)。