Unique rows
Unique rows
(OP)
Hello all,
please conside the following table "photo"
id employee_id photo_name
---------------------------------------
1 2 abc.jpg
2 2 xyz.jpg
3 5 acd.jpg
4 2 sis.jpg
5 3 sfs.jpg
6 5 iii.jpg
7 2 ier.jpg
---------------------------------------
now what I want is this table should select all the fields with unique employee_id (i.e. query should select total 3 rows with employee id 2,3,5) and everythime the query should select different picture(which can be done using random() )
Can anyone help me with this problem?
Thank you,
newfriends1981
please conside the following table "photo"
id employee_id photo_name
---------------------------------------
1 2 abc.jpg
2 2 xyz.jpg
3 5 acd.jpg
4 2 sis.jpg
5 3 sfs.jpg
6 5 iii.jpg
7 2 ier.jpg
---------------------------------------
now what I want is this table should select all the fields with unique employee_id (i.e. query should select total 3 rows with employee id 2,3,5) and everythime the query should select different picture(which can be done using random() )
Can anyone help me with this problem?
Thank you,
newfriends1981
RE: Unique rows
CODE
employee_id,(
select
photo_name
from photo
where p.employee_id=employee_id
order by random()
limit 1
) as photo_name
from photo p
group by employee_id
Feherke.
http://rootshell.be/~feherke/