如果子查询(内部查询)将零值返回到外部查询,如何处理如何处理
我有一个类似的垂直
id | profile_id | feature_id | value |
---|---|---|---|
1 | 1 | 1 | rick |
2 | 1 | 2 | Novak |
3 | 5 | 3 | 5428 |
4 | 5 | 1 | Joe |
... | ... | ... | : |
表
我有一个查询:
SELECT * FROM(SELECT `value` TelNum FROM `profile_features` WHERE `feature_id` IN (10, 64, 103) AND `profile_id` = 16752 LIMIT 1) as TelNum,
(SELECT `value` NCode From `profile_features` WHERE `feature_id` IN (5, 61, 100) AND `profile_id` = 16752 LIMIT 1) AS NCode,
(SELECT `value` Fname From `profile_features` WHERE `feature_id` IN (1, 55, 86) AND `profile_id` = 16752 LIMIT 1) AS Fname,
(SELECT `value` Lname From `profile_features` WHERE `feature_id` IN (2, 56, 95) AND `profile_id` = 16752 LIMIT 1) AS Lname
但是,如果其中一个子查询返回null,则查询没有任何输出。
我想要Telnum,ncode,fname,lname的行结果,它们要么为null或不为空。
I have a vertical table like this:
id | Profile_id | feature_id | value |
---|---|---|---|
1 | 1 | 1 | Rick |
2 | 1 | 2 | Novak |
3 | 5 | 3 | 5428 |
4 | 5 | 1 | Joe |
... | ... | ... | ... |
(above table is short part of profile_features table)
I have a query:
SELECT * FROM(SELECT `value` TelNum FROM `profile_features` WHERE `feature_id` IN (10, 64, 103) AND `profile_id` = 16752 LIMIT 1) as TelNum,
(SELECT `value` NCode From `profile_features` WHERE `feature_id` IN (5, 61, 100) AND `profile_id` = 16752 LIMIT 1) AS NCode,
(SELECT `value` Fname From `profile_features` WHERE `feature_id` IN (1, 55, 86) AND `profile_id` = 16752 LIMIT 1) AS Fname,
(SELECT `value` Lname From `profile_features` WHERE `feature_id` IN (2, 56, 95) AND `profile_id` = 16752 LIMIT 1) AS Lname
but if one of the subqueries returns null, query have not any output.
I want a row result with TelNum, NCode, Fname, Lname either they are Null or not null.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在当前的笛卡尔产品中使用Select List中的标量子查询:
另外,您可以学习使用左外的Join:
You could use scalar subqueries in the select-list instead of your current Cartesian product:
Alternatively, you could learn to use LEFT OUTER JOIN: