I want to select unique images from a database. I am using the following query which includes a specific image, (ID=11), but I’m getting some repeated images:
$photo=mysql_query("SELECT A. * FROM (
SELECT * FROM profile_images
WHERE approved='N'
ORDER BY (ID = 11) DESC, RAND()
LIMIT $sn)
as A ORDER BY RAND()");
Where can I put DISTINCT? I have tried:
$photo=mysql_query("SELECT A. * FROM (
SELECT DISTINCT FROM profile_images
WHERE approved='N'
ORDER BY (ID = 11) DESC, RAND()
LIMIT $sn)
as A ORDER BY RAND()");
But I’m getting this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘FROM profile_images WHERE approved=’N’ ORDER BY (ID = 11) DESC, RAND(‘ at line 2
you can use
DISTINCTbut you are not selecting any columns in your sub-query. You have to add the columns you want orselect *change you current query from this:
to this: