문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top