如何从 Ingres 的虚拟表中选择零或一条记录
在大多数 SQL 产品中,我可以从无表或虚拟表中进行选择,如下所示:
-- Oracle
SELECT 1 FROM DUAL
-- Many other SQL products (including Ingres)
SELECT 1
有时,我想在上述语句中添加一个条件,以便根据条件检索 0 或 1 条记录
-- Oracle
SELECT 1 FROM DUAL WHERE 1 = 0
-- Many other SQL products (but not Ingres)
SELECT 1 WHERE 1 = 0
但上面的情况并没有适用于 Ingres 10.0。我该怎么做呢?
In most SQL products, I can select from no table or from a dummy table like this:
-- Oracle
SELECT 1 FROM DUAL
-- Many other SQL products (including Ingres)
SELECT 1
Sometimes, I want to add a condition to the above statement, in order to retrieve 0 or 1 record, depending on the condition
-- Oracle
SELECT 1 FROM DUAL WHERE 1 = 0
-- Many other SQL products (but not Ingres)
SELECT 1 WHERE 1 = 0
But the above does not work for Ingres 10.0. How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有使用过 Ingres,但我从你的问题中假设,如果有
WHERE
,则FROM
是强制性的? 怎么样在这种情况下, Or
(最后一个总是返回一行,但允许您检查条件)
I've not used Ingres but I assume from your question that a
FROM
is mandatory if there is aWHERE
? In that case how aboutOr
(The last one will always return a row but allow you to check a condition)
据我所知,系统目录 iidbconstants 只有一行,因此您可以使用它。我无法想到有多行的情况,但您可能需要添加 DISTINCT 以防万一:
AFAIK the system catalog iidbconstants only has one row, so you could use that. I can't think of a case where there are multiple rows but you may want to add a DISTINCT in case: