A
A
astrotrain2016-01-28 23:14:01
MySQL
astrotrain, 2016-01-28 23:14:01

How to add incremental field to mysql output?

I don’t know how to call it correctly, but in general I need to display some data and that with each entry a field is displayed indicating its number. Like this:

row1: field1, field2, 1
row2: field1, field2, 2
...
rowN: field1, field2, N

That is, this data is not stored in tables, but generated during output. There seems to be some sort of procedure?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2016-01-29
@Immortal_pony

SET @id = 0;
;
SELECT 
    @id := @id+1,
    table.`field1`,
    table`field2`
FROM `table`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question