Can I join a SELECT and UPDATE statement? If so, how can I do this?
I have a table whose name is news .
I display news on my website. If someone reads the news, I add 1 to the hit . I am doing this with two queries:
mysql_query("SELECT * FROM news WHERE id=2 LIMIT 1");
mysql_query("UPDATE news SET hit=hit+1 WHERE id=2");
But I want to join them.
id | title | content |hit
---+-----------+-------------------+---
1 | sdfsdfdsf | dfsdffdsfds836173 |5
2 | sfsdfds | sdfsdsdfdsfdsfsd4 |9
3 | ssdfsdfds | sdfdsfs |3
Update: OP wants to update and select the updated rows in a single SQL statement.
source
share