Home » RDBMS Server » Server Administration » Is there a query for this case?
Is there a query for this case? [message #371749] Fri, 01 December 2000 12:48 Go to next message
John Armani
Messages: 3
Registered: December 2000
Junior Member
Say I have a table with the following data:
Id Grade
-- -----
1 A
2 B
3 C
4 A
5 B
6 A
7 D

I would like a query to return all id/grade combinations where there are multiple ids with the
same grade (and order by Grade). The query would return the following from the above table...

Id Grade
-- -----
1 A
4 A
6 A
2 B
5 B
Is it possible through a single query? Any clues would be greatly appreciated.

John
armani@armani.rochny.uspra.abb.com
Re: Is there a query for this case? [message #371750 is a reply to message #371749] Fri, 01 December 2000 14:08 Go to previous messageGo to next message
Elena
Messages: 14
Registered: December 2000
Junior Member
SELECT ID, GRADE
FROM TABLE_NAME
ORDER BY GRADE;
Re: Is there a query for this case? [message #371751 is a reply to message #371750] Fri, 01 December 2000 14:47 Go to previous messageGo to next message
John Armani
Messages: 3
Registered: December 2000
Junior Member
This query will return all rows. I want to exclude rows where the grade is referenced by only one id.
Re: Is there a query for this case? [message #371752 is a reply to message #371749] Fri, 01 December 2000 15:29 Go to previous messageGo to next message
Elena
Messages: 14
Registered: December 2000
Junior Member
Is it OK?
SQL> SELECT ID, GRADE
FROM A
WHERE GRADE IN (SELECT GRADE
FROM A
HAVING COUNT(GRADE)>1
GROUP BY GRADE);

ID GRADE
--------- ---
1 A
4 A
6 A
2 B
5 B
Re: Is there a query for this case? [message #371773 is a reply to message #371752] Mon, 04 December 2000 09:55 Go to previous message
John Armani
Messages: 3
Registered: December 2000
Junior Member
Elena - thanks for the help!
Previous Topic: packages
Next Topic: get sql_text within trigger
Goto Forum:
  


Current Time: Sun Dec 22 19:50:13 CST 2024