In a query add data only to the first data obtained - SQL

-1

I have a table with X number of records, but I'm interested that only the first record can be given an extra data, this can be by identifier field , that is, the smallest identifier, this only in order to identify which was the first record to be obtained, at the same time obtain the rest of the data. I guess it would be with CASE but I'm not sure.

Thank you.

Example of output:

------------------------------
| ID  |Nombre    | Expr1     |
------------------------------
| 4   |Omar      | 1         |
| 9   |Juan      | 0         |
| 13  |Maria     | 0         |
| 14  |Lupita    | 0         |

-Where Expr1 would be the extra data generated by the SQL query.

I would assume it would be something like that, but the syntax is wrong:

SELECT id, nombre, CASE id WHEN MIN(id) THEN '1' ELSE '0' END 'Expr1' FROM tbl_contenido
    
asked by Abraham Montes 21.05.2018 в 18:05
source

1 answer

1

There is a conceptual error in your question. What is the first data obtained?

Actually, in a database, there is no first data obtained. No database engine ensures that the first record obtained is the first of any kind, unless you make an order by. There is no order in the records, unless you add a timestamp, or the base is configured to save input logs and see the timestamp entry of the records.

All this said, since this answer does not really answer your question, you could explain why adding something to a record that you do not really know what it is, or if you know what it is, explain what query you tried until now or why Is the first record? Once that is done, I edit the answer with whatever you need.

    
answered by 21.05.2018 / 18:10
source