我正在尝试创建一个查询,其中第一个查询将返回COLUMN,根据第一个查询的结果将执行第二个查询:
SELECT OBJECT_ID from test.CORRELATION_SET
WHERE (NAME='STATUS' AND VALUE ='SUCCESS')
|OBJECT_ID|
|---------|
|A |
|B |
|C |
|---------|
SELECT * FROM test.CORRELATION_SET
WHERE OBJECT_ID = ('A'|'B'|'C');
答案 0 :(得分:3)
以下是查询
SELECT * FROM CORRELATION_SET
WHERE OBJECT_ID in (
SELECT OBJECT_ID from CORRELATION_SET
WHERE (NAME='STATUS' AND VALUE ='SUCCESS')
)
答案 1 :(得分:1)
你的例子没有意义,看起来你错过了在第二个查询中命名的表。
SELECT * from test.CORRELATION_SET WHERE (NAME='STATUS' AND VALUE ='SUCCESS')
上述查询将返回与两个查询相同的结果。假设您的第二个查询使用了一个名为CORRELATION_SET2
的表,您可以使用Kumar在其评论中使用的嵌套查询。您也可以使用联接。
SELECT set2.* FROM test.CORRELATION_SET set1
JOIN test.CORRELATION_SET2 set2 ON set2.object_id = set1.object_id
WHERE
set1.name = 'status' and set1.value = 'success';