SQL 如何将第一个查询的输出(有两个值)作为第二个查询的输入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4744019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to give the output of the first query(which has two values) as the input to the second?
提问by abhijithln
i get 2 names as the output of the first query.... eg: paul,peter now this should be the input for the second query, which has to display paul's and peter's email ids....
我得到 2 个名字作为第一个查询的输出......例如:paul,peter 现在这应该是第二个查询的输入,它必须显示 paul 和 peter 的电子邮件 ID......
回答by Alexander Malakhov
For nested queries I would strongly recommend WITH
clause. It makes long complex queries order of magnitude easier to understand / construct / modify:
对于嵌套查询,我强烈推荐WITH
子句。它使长时间复杂的查询更容易理解/构造/修改:
WITH
w_users AS( -- you can name it whatever you want
SELECT id
FROM users
WHERE < long condition here >
),
w_other_subquery AS(
...
)
SELECT email_id
FROM ...
WHERE user_id IN (SELECT id FROM w_users)
回答by Harish
You can use like this
你可以这样使用
LIKE
喜欢
SELECT USER_ID,EMAIL_ID FROM USERS where user_id IN
(SELECT PRODUCT_MEMBERS FROM PRODUCT WHERE PRODUCT_NAME='ICP/RAA');
Just use the IN clause '=' is used for matching one result
只需使用 IN 子句 '=' 用于匹配一个结果
回答by Jayant Bramhankar
You can use In Command to get result ex:
您可以使用 In Command 来获取结果,例如:
SELECT email FROM tableName WHERE (Name IN ('paul', 'peter'))