0

MySql 8

I have this table:

id name count
1 name1 3
2 name2 4

I'm looking for a way to increment count each time I get the count value.

Something like:

SELECT count FROM table WHERE id = 1 AND /*increase count value*/;

So this request will return: 3

Then if I do:

SELECT * FROM table;

I got:

id name count
1 name1 4
2 name2 4

I'm assuming I have to use an Index but I can't figure out how.

Thank you

Akina
  • 39,301
  • 5
  • 14
  • 25
Lenny4
  • 1,215
  • 1
  • 14
  • 33
  • This is not possible by the query - SELECT query does not produce any event itself. You may create SP for both UPDATE and SELECT. – Akina Oct 01 '21 at 18:40
  • Are you trying to keep track of how many times you've used a certain piece of data? – Xammax Oct 01 '21 at 18:42
  • do you mean increment the count in your results or increment the count in your table? if the latter, you would use a stored procedure for this, to increment the count and return the row's data – ysth Oct 01 '21 at 18:45
  • @ysth, I mean increment the count in the table as shown on my example. – Lenny4 Oct 01 '21 at 19:44

1 Answers1

0

As @Xammax's answer didn't suit my need, I change my database from mysql to postgre and use this answer: Return updated row attributes on UPDATE

Lenny4
  • 1,215
  • 1
  • 14
  • 33