Wait, that's wrong.
Main Topics
Browse All TopicsHi all,
I have a table with the following data.
name manager
------- -----------
Pankaj Suneel
Gaurav Suneel
Pankaj Ahmed
Sangeetha Ahmed
Gaurav Ahmed
For each unique name, I want to get any one row from the table. I mean to say, since there are 3 unique names (Pankaj, Gaurav, Sangeetha), I want any rows for them. The sample output would be
Pankaj Suneel (Or Pankaj Ahmed will also do)
Gaurav Suneel (Or Gaurav Ahmed will also do)
Sangeetha Ahmed (Because there is a single row).
I am confused. Please help me.
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
All tables, by definition, have a primary key. If you have not explicitly defined one, then the key is every column in the table. That may or may not be desirable in this case (from the sample of data you provided it sounds reasonable). You may want to make sure it is explicitly declared as such so the DBMS will at least know what you're doing.
In any case, SELECT MIN(manager) FROM the_table GROUP BY name
... is just as good as anything. Pick your favorite aggregation function and run with it, basically, since you don't care which row gets returned.
VoteyDisciple, can u explain if ur query does exactly wat is required ? Please correct me if im wrong, but this is wat i believe vil happen : -
>> SELECT MIN(manager) FROM the_table GROUP BY name --- selects a single manager for every name.
>> SELECT name, manager FROM the_table WHERE manager IN (SELECT MIN(manager) FROM the_table GROUP BY name) --- selects name, manager from the_table having manager in the the above list i.e. select name, manager from the_table where manager is in the list of a manager for every name, NOT that specific one. This query night return multiple records for the same name, which is not desired. I suppose u missed and a WHERE condition.
I guess the below query wud the requried : -
SELECT name, (SELECT MIN(manager) FROM the_table WHERE name = t.name)
FROM the_table t
GROUP BY name
Yeah, I didn't properly think that through after revising what the primary key is. You're right; my query will just select... well, nothing of particular value -- all the names associated with a bunch of managers selected by no thought-out criterion.
jinesh_kamdar's solution is more appropriate in this schema -- select the name, and the minimum manager for that name.
Business Accounts
Answer for Membership
by: ivanovnPosted on 2006-11-06 at 10:31:56ID: 17883153
SELECT name, manager
FROM table1
WHERE name IN (SELECT DISTINCT name FROM table1)