時間:2024-03-04 00:33作者:下載吧人氣:23
exists和in的區(qū)別很小,幾乎可以等價,但是sql優(yōu)化中往往會注重效率問題,今天咱們就來說說exists和in的區(qū)別。
exists語法:
select … from table where exists (子查詢)
將主查詢的結(jié)果,放到子查詢結(jié)果中進(jìn)行校驗,如子查詢有數(shù)據(jù),則校驗成功,那么符合校驗,保留數(shù)據(jù)。
create table teacher
(
tid int(3),
tname varchar(20),
tcid int(3)
);
insert into teacher values(1,’tz’,1);
insert into teacher values(2,’tw’,2);
insert into teacher values(3,’tl’,3);
網(wǎng)友評論