6

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?

2
  • such a question has been asked many times before, please do some research before asking on SO Commented Jul 6, 2015 at 8:55
  • I can't think of a reason to use the 1-st option in this case. Commented Jul 6, 2015 at 8:58

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.