我有一个问题,在我的数据中,我将返回一条记录,其中列值看起来像
- 询问
Select col1 from myTable where id = 23
-- col1 111, 104, 34, 45 的结果
我想将这些值提供给 in 子句。到目前为止,我已经尝试过:
-- 查询 2 -- 尝试 1
Select * from mytableTwo
where myfield in (
SELECT col1
from myTable where id = 23)
-- 查询 2 -- 尝试 2
Select * from mytableTwo
where myfield in (
SELECT '''' +
Replace(col1, ',', ''',''') + ''''
from myTable where id = 23)
-- 查询 2 测试 -- 这有效并且会返回数据,所以我在这里验证数据是否存在
Select * from mytableTwo
where myfield in ('111', '104', '34', '45')
为什么查询 2 尝试 1 或 2 不起作用?