MySQL Forums
Forum List  »  Newbie

Trying to figure out a statement
Posted by: josh
Date: April 19, 2005 02:11PM

Hi,

I have a table which includes the fields 'category' and 'picture'. I'll give this for an example:

Category | Picture
----------------------
Cat1 pic1.jpg
Cat1 pic2.jpg
Cat1 pic3.jpg
Cat2 pic4.jpg
Cat2 pic5.jpg
Cat3 pic6.jpg

I am trying to figure out how to return a list of each distinct category, but also return a single picture with each distinct category. What I mean is, I want a list like:

Category | Picture
----------------------
Cat1 pic3.jpg
Cat2 pic4.jpg
Cat3 pic6.jpg

I'm not concerned which picture is returned.

So it won't work if I use 'SELECT DISTINCT category' because it will only return the category, and no picture. And I know if I use 'SELECT DISTINCT category, picture' will return all of the fields because they are all distinct by that logic. I'm sure there is a simple solution to this which I have not been able to find in my research. Any help is greatly appreciated.

Options: ReplyQuote


Subject
Written By
Posted
Trying to figure out a statement
April 19, 2005 02:11PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.