简体   繁体   中英

php/mysql: select from table and update in one query

I'd like to know whether it is possible / advisable (why?), to select data from a table and update the same entry in the same pass

Example

 SELECT message_content, message_times_read FROM messages WHERE message_id = 1

Then

UPDATE messages SET message_times_read = message_times_read + 1 WHERE message_id = 1

Can I do them in one call? More importantly, if this is possible, should I? (ie is this considered proper practice, is this compatible across different versions, is there performance benefit?)

You must to create a Trigger if you want to do multiples queries in a same query. Check this link if you want to lear more about it: https://www.sitepoint.com/how-to-create-mysql-triggers/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM