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

Goma
  • 2,018
  • 1
  • 10
  • 19
Nicholaos Renessis
  • 432
  • 1
  • 4
  • 8

1 Answers1

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.

MatthewJ
  • 3,127
  • 2
  • 27
  • 34