how to retrieve just one item from a query

Last Post 09 Apr 2007 11:56 AM by aashishshrestha. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
aashishshrestha
New Member
New Member

--
09 Apr 2007 09:47 AM
TABLE XYZ has cols id,item_name,type

with the following data
id,item_name,type
1,banana,fruit
2,apple,fruit
3,doritos,chips
4,lays,chips,
5,coke,drinks
6,pepsi,drinks
7,mtdew,drinks
8,carrots,vegetable
9,onions,vegetable

from this table if i just wanted to return one item for each type how would i do it?

looking for some output like
banana,fruit
lays,chips
coke,drinks
carrots,vegetables

the item_name that is returned does not matter

nosepicker
New Member
New Member

--
09 Apr 2007 10:04 AM
If the item_name does not matter, you can use either MAX or MIN to retrieve a single item:

SELECT MIN(item_name), type
FROM XYZ
GROUP BY type
aashishshrestha
New Member
New Member

--
09 Apr 2007 11:56 AM
thank you that worked perfectly
You are not authorized to post a reply.

Acceptable Use Policy