Jason
Jason

Reputation: 52533

Artificially Add a Record To MySQL Results

Is there any way to slip in a record to the top of a result set in MySQL? For instance, if my results are:

1 | a
2 | b
3 | c
etc

I want to be able to get:

Select | Select
1      | a
2      | b
3      | c
etc

Where "Select" isn't actually a part of the recordset, but artificially inserted.

Thanks.

Upvotes: 3

Views: 193

Answers (4)

jsr
jsr

Reputation: 1329

If your query is

SELECT Colum1, Column2 FROM Table

try

SELECT Column1, Column2 FROM Table UNION SELECT 'Select', 'Select'

Upvotes: 3

Chris McCall
Chris McCall

Reputation: 10407

SELECT "Select" as col1, "Select" as col2
UNION
SELECT col1, col2 FROM table

Upvotes: 4

VoteyDisciple
VoteyDisciple

Reputation: 37813

The only way to achieve that with a query would be using UNION:

SELECT 'Select', 'Select'
UNION
SELECT ...

Getting the order correct will depend on how you want the results ordered overall.

If the goal is simply to get a heading at the top of the results, it would be easier (plus more efficient) to just add programmatically in the application that's receiving the data.

Upvotes: 6

pilsetnieks
pilsetnieks

Reputation: 10420

Union.

select "Select", "Select"
union
select Col1, Col2 from Table1

Upvotes: 2

Related Questions