This question already has an answer here:
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.
</div>
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.