求助一条sql。大家帮忙看看。
id 商品id 参数id
1 35 1
2 35 2
3 38 1
4 38 3
5 37 1
以参数id为条件查询商品id,如输入1查询35 37 38 再输入2 需要把1条件累加 查询出 35
本人想法是 自连查询, 请问有什么效率更高的方法,因为如果查询条件过多,会导致自连N次。
[解决办法]
select *
from table1 t
where 参数id = 2
and exists (select 1 from table1 where 参数id = 1)
[解决办法]