4

What do you think is faster?

SELECT DISTINCT(user_id) FROM myTable;

Then fetch to $myArray.

Or

SELECT user_id FROM myTable;

Then fetch to $myArray and do

$myArray = array_unique($myArray);

Note: user_id is a FOREIGN KEY CONSTRAINT

1 Answer 1

6

For speed and memory efficiency, you want to return the minimum amount from the database without putting unnecessary rows for processing/memory efficiency. So, the distinct in this case is the better choice.

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

1 Comment

+1 As a rule of thumb, if MySQL can do it, it's typically faster and more efficient.

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.