java - 创建一个选择查询,如果 id 不存在,那么对于该 id,它应该在 SQL 中返回 null
解决方案
One idea is to build a derived table that holds the values you seach for, and then bring the original table with a left join
. In SQL Server, you would use values()
:
select v.b, t.*
from (values(111), (777), (888)) v(b)
left join mytable t on t.b = v.b
order by v.b
I added a column that holds the value that was intially searched for, since it makes more sense to me - you can remove it if needed.
Oracle does not support this syntax; a (lenghtier) alernative is union all
and from dual
:
select v.b, t.*
from (
select 111 b from dual
union all select 777 from dual
union all select 888 from dual
) v
left join mytable t on t.b = v.b
order by v.b
推荐阅读
- python - 即使在定义 lamda_handler 之后,模块 'lambda_function' 上也缺少处理程序 'lambda_handler'
- decimalformat - 无法提供小于小数位数定义的十进制字段
- azure - 如何通过 REST API 仅获取已发布的资产
- java - 运行 RestAssured 时出现 java.net.UnknownHostException
- php - 如何通过删除浏览器的默认页眉和页脚在 Chrome 中的 window.print() 中设置每个页面的页码
- android - 适用于中国 android 用户的 Flutter 应用程序
- python - 如何将DataFrame中的对象转换为字符串
- android - 将 Circleimageview 的状态保存在片段内
- java - 发布约会/预订 - CORS 政策问题
- javascript - 引导模式未在 PHP 中显示