简体   繁体   English

使用select为查询结果添加行

[英]Add row to query result using select

Is it possible to extend query results with literals like this? 是否可以使用这样的文字扩展查询结果?

select name from users
union
select name from ('JASON');

or 要么

select age, name from users
union
select age, name from (25,'Betty');

so it returns all the names in the table plus 'JASON', or (25,'Betty'). 所以它返回表中的所有名称加'JASON'或(25,'Betty')。

You use it like this: 你这样使用它:

SELECT  age, name
FROM    users
UNION
SELECT  25 AS age, 'Betty' AS name

Use UNION ALL to allow duplicates: if there is a 25-years old Betty among your users, the second query will not select her again with mere UNION . 使用UNION ALL允许重复:如果您的用户中有25岁的Betty,则第二个查询不会仅使用UNION再次选择她。

In SQL Server, you would say: 在SQL Server中,您会说:

Select name from users
UNION [ALL]
SELECT 'JASON'

In Oracle, you would say 在Oracle中,你会说

Select name from user
UNION [ALL]
Select 'JASON' from DUAL

is it possible to extend query results with literals like this? 是否可以使用这样的文字扩展查询结果?

Yes. 是。

Select Name
From Customers
UNION ALL
Select 'Jason'
  • Use UNION to add Jason if it isn't already in the result set. 如果Jason不在结果集中,请使用UNION添加Jason。
  • Use UNION ALL to add Jason whether or not he's already in the result set. 使用UNION ALL添加Jason,无论他是否已经在结果集中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM