Unique Image Query

Hi,

I am having trouble achieving the outcome I am looking for with a mysql
query.

The query below pulls information from two tables: profile_images and
name_list.

It pulls 6 random images where the name_list.id matches the
profile_images.vref but also checks that the 'class' field from name_list is
equal to '5'.

$index_thumbs = mysql_query("SELECT DISTINCT * FROM profile_images,
name_list
WHERE profile_images.vref = name_list.id AND name_list.class = '5'
ORDER BY RAND() LIMIT 0,6");


This is working fine for pulling 6 random images that meet those
requirements but I would also like to to make the profile_images.vref /
name_list.id UNIQUE as there are multiple images for each each
name_list.id - So therefore I would like to return 6 unique images from 6
id's in the name_list rather than having cases where multiple images show up
from one name_list.id

I'm hoping this is going to be a simple adjustment to someone who knows what
they're doing :)

Thanks in advance.

Steve
Steve [ Do, 23 August 2007 09:01 ] [ ID #1803234 ]

Re: Unique Image Query

Steve wrote:

> I'm hoping this is going to be a simple adjustment to someone who knows what
> they're doing :)


You could try to GROUP BY on name_list.id.


--

//Aho
Shion [ Do, 23 August 2007 18:19 ] [ ID #1803235 ]

Re: Unique Image Query

Perfect :)


Thanks


"J.O. Aho" <user [at] example.net> wrote in message
news:5j5qd6F3sd2j7U1 [at] mid.individual.net...
> Steve wrote:
>
>> I'm hoping this is going to be a simple adjustment to someone who knows
>> what
>> they're doing :)
>
>
> You could try to GROUP BY on name_list.id.
>
>
> --
>
> //Aho
Steve [ Fr, 24 August 2007 03:41 ] [ ID #1804215 ]
PHP » alt.php.sql » Unique Image Query

Vorheriges Thema: MAXIMUM LENGTH OF LONGTEXT FIELD
Nächstes Thema: href in mysql databse