select * from table1 where col1 in (select colxx from table2 where....)
这样的子查询是没有问题的
但是我想实现下面的子查询,可以吗?
select * from table1 where col1 > (select colxx from table2 where id=‘id’)
子查询的结果,我可以保证是一条(id为主键),但是好像不能这么用啊。
有什么方法能够代替吗?
要求在SQL语句中实现,不使用存储过程
------解决方案--------------------
如果你能保证子查询返回的是一条记录,并且返回的是number,那么这个语句是可以执行的。
如果实在不行的话你就用exists来实现吧
select *
from table1 t1
where exists (select 1
from table2 t2
where id = ‘id’
and t1.col1 > t2.colxx)