Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select distinct

Status
Not open for further replies.

twetty1

Programmer
Jun 19, 2003
4
CA
Hi,
What's wrong with this expression:
SELECT * from table group by nom;
I have this error message of Oracle
ORA-00979: not a GROUP BY expression

Thanks
 
It's telling you that it doesn't know how to combine records so that only unique values of "nom" will appear. For example, if you had a table like
Code:
nom     Field2     Field3
Code:
 A        10          ABC
 A        12          XXX
Oracle can't determine how to deal with different values of Field2 and Field3 while displaying only one value ("A") for nom.
 
I want to have a group by with field2 and field3. How can i do it?
 
You can have as many fields as you want in your GROUP BY

SELECT * from table group by nom, Field1, Field2

Note however that you are retrieving all ("*") fields from the table. You can of course GROUP BY all of them but that's the same as not grouping at all ... assuming that your table doesn't contain duplicate records.

The better question is probably "Why do you want to group records at all?" Are you trying to Count them? Sum them? Find Min or Max Values?

The title of your post is "Select Distinct". Do you just want to

SELECT DISTINCT * from table

(Again somewhat pointless since it will still display every record as long as you are retrieving all fields.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top