Saturday, February 25, 2012

retrieve only 1 row for each ID (was "Help on SQL! Urgent..")

i have a table called tblpictures which look something like this..

filename|ID
----
1 |p1
2 |p1
3 |p2
4 |p2
5 |p3

is there a way to retrieve only 1 row for each ID? how will the select statement looks like?? please help me..Which row would you want?

If you just want a distinct list of IDs, then this will do:

select distinct ID from YourTable|||erm no i want to show 1 filename and 1 ID for each ID|||You could probably get away with :

select max(filename), id from tblPictures group by id

if this is what you are looking for ...

:cool:

No comments:

Post a Comment