0

I would like to keep track how many times a row was returned in a mysql query. Is there a way to INCREMENT row data as it is selected? I would like to do this in one shot vs running two queries.

So a rough idea,

SELECT * FROM data WHERE text in($search) & UPDATE hits=hits+1

Something like that.

j08691
  • 204,283
  • 31
  • 260
  • 272
btaylor507
  • 211
  • 1
  • 13

1 Answers1

0

SELECT * FROM data WHERE text in($search) & UPDATE hits=hits+1

Assuming hits is in data, you can do this in two queries like so:

UPDATE data
SET hits=hits+1
WHERE text in($search);

SELECT * FROM data WHERE text in($search);

Postgres would allow you to do it in a single statement with a returning * clause on the update statement, but that's about it.

Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154