Inside the MySQL database manager I have a table of which I do a% general% co_ and I want to list with an incremental number all records, I can do it originally with a user defined variable as follows :
SET @counter = 0;
SELECT (@counter := @counter + 1) AS NP, name, email FROM profiles;
It is important to mention that for the variable
SELECT
to go increasing the value you need the syntaxcounter
otherwise only the:=
symbol is used regardless of how many records exist it will keep the same declared value at the beginning.
The result I get is the following
+------+--------------+------------------+
| NP | name | email |
+------+--------------+------------------+
| 1 | dfsdfsf | dsfdsfsf |
| 2 | alfa | [email protected] |
| 3 | danielo | [email protected] |
| 4 | ortega oga | [email protected] |
| 5 | diana | [email protected] |
| 6 | elena | [email protected] |
| 7 | gonzalo | [email protected] |
| 8 | jorge | [email protected] |
| 9 | mendez | [email protected] |
| 10 | pedro | [email protected] |
| 11 | arnoldo | [email protected] |
+------+--------------+------------------+
However I do not want to depend on this option since I need to know how to do it with a =
to avoid being declared variables