Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert dummy row in SQL select query

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.

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.

like image 242
Bilal Ahmed Avatar asked Dec 14 '14 08:12

Bilal Ahmed


People also ask

How do I add another row to a select query?

To insert a row into a table, you need to specify three things: First, the table, which you want to insert a new row, in the INSERT INTO clause. Second, a comma-separated list of columns in the table surrounded by parentheses. Third, a comma-separated list of values surrounded by parentheses in the VALUES clause.

How do I insert a Rownum into a table in SQL?

To add a row number column in front of each row, add a column with the ROW_NUMBER function, in this case named Row# . You must move the ORDER BY clause up to the OVER clause.


1 Answers

SELECT 0 AS Id, 'All' AS Name
UNION ALL
SELECT Id, Name FROM Users;
like image 166
Rob Farley Avatar answered Oct 11 '22 23:10

Rob Farley