Should I do single more complex MySQL query or multiple simpler queries with PHP?
For example
Simpler queries:
UPDATE image SET profile = 0 WHERE user_id = 1;
UPDATE image SET profile = 1 WHERE user_id = 1 AND id = 10;
One single more complex query:
UPDATE image
SET profile = CASE id WHEN 10 THEN 1 ELSE 0 END
WHERE user_id = 1;
1: What is fastest and most efficient?
2: What is considered to be best practice, or preferred method?
One single query is fastest and most efficient
Besides the IF statement, MySQL also provides an alternative conditional statement called MySQL CASE. The MySQL CASE statement makes the code more readable and efficient. See more details... http://www.mysqltutorial.org/mysql-case-statement/
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.