在 SQL 选择查询中插入虚拟行 [英] Insert dummy row in SQL select query

查看:32
本文介绍了在 SQL 选择查询中插入虚拟行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 SQL Server 存储过程.我有一个包含字段(ID、姓名、电子邮件、地址)的用户"表.

I am working on SQL Server stored procedure. I have a table 'User' having fields (Id, Name, Email,Address).

我有以下查询返回所有用户

I have following query returning All Users

select * from [User]

它返回所有用户,但我只想在返回之前将以下虚拟用户插入到结果记录中.

It returns all users, but I just want to insert following dummy user to resulting record before returning it.

用户 => Id = 0, Name = "All"

User => Id = 0, Name = "All"

此记录不会出现在数据库中,但在返回结果时,我想将此记录插入为第一条记录,然后插入剩余的用户.我试图找到类似的东西,但徒劳无功.

This record will not be present with in the database but while returning result I want to insert this record as first record and then remaining users. I tried to find something like this but in vain.

推荐答案

SELECT 0 AS Id, 'All' AS Name
UNION ALL
SELECT Id, Name FROM Users;

这篇关于在 SQL 选择查询中插入虚拟行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆