使用select后面的数字表示什么?

问题描述 投票:1回答:1

有两个表:

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)

我已经在线搜索了一些信息,但一无所获。

mysql select exists
1个回答
0
投票

SELECT 1就是这样:选择值1。与WHERE EXISTS一起使用时,子查询返回什么数据都没有关系,只要它返回任何数据即可(换句话说:返回至少一行)。

© www.soinside.com 2019 - 2024. All rights reserved.