I have the following query but it’s returning multiple entries from the profile_photos table. Is it possible to return just one random entry from the profile photos table? If not random is it possible to limit the number of results to 1?
Here is my current query:
$sql = "SELECT * FROM login_users " .
"LEFT JOIN profile_photos ON profile_photos.user_id = login_users.user_id " .
"LEFT JOIN profiles ON profiles.user_id = login_users.user_id " .
"WHERE login_users.restricted <> 1 " .
"ORDER BY login_users.birthdate DESC " .
"LIMIT 0, 20";
Here is one method. Look up a random photo and then join in the additional information:
This assumes that photo_id is the primary key on profile_photos.