表table_1其中有两个字段:
id和name。有一句sql语句:
select *
from table_1
where id = XXX(比如:select id from ...);
(XXX的值有n个,是表里的n个id,如果是等于一个值的话,是没有问题的;但是有n个,怎么办?)
是不是一定要循环,一定用到写存储过程和游标?这会儿估计快要下班了!大家辛苦了!
id和name。有一句sql语句:
select *
from table_1
where id = XXX(比如:select id from ...);
(XXX的值有n个,是表里的n个id,如果是等于一个值的话,是没有问题的;但是有n个,怎么办?)
是不是一定要循环,一定用到写存储过程和游标?这会儿估计快要下班了!大家辛苦了!
from table_1
where exists select 1 from table_2 where table_2.id=table_1.id;
from table_1
where exists select 1 from table_2 where table_2.id=table_1.id;exists 和 in 都可以,但是这两个稍微有点区别:如果table_2中的记录数比table_1中的数据多很多,那么用in,否则用exists。
考虑到性能上,这样能提高查询效率
from table_1
where id in (select id from ...)