Home » SQL & PL/SQL » SQL & PL/SQL » Need help with a SQL Query (Oracle 10g)
Need help with a SQL Query [message #427738] Sat, 24 October 2009 10:57 Go to next message
SQLTester
Messages: 1
Registered: October 2009
Junior Member
Hi All,

The table has 2 columns: ID and Role. Here is the structure of the table:

ID Role
--- ------
A Manager
A Tester
A Director
B Manager
B Tester
C Tester

Now the question is: I would like to display the roles which have multiple ID. For example: Manager has ID A and B.
Re: Need help with a SQL Query [message #427740 is a reply to message #427738] Sat, 24 October 2009 11:36 Go to previous messageGo to next message
Littlefoot
Messages: 20888
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Research use of GROUP BY and HAVING clauses in the documentation.
Re: Need help with a SQL Query [message #427742 is a reply to message #427738] Sat, 24 October 2009 11:38 Go to previous messageGo to next message
Michel Cadot
Messages: 64102
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Use COUNT, GROUP BY, HAVING

Post a working Test case: create table and insert statements along with the result you want with these data.

Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version with 4 decimals.

Regards
Michel
Re: Need help with a SQL Query [message #427860 is a reply to message #427738] Mon, 26 October 2009 04:35 Go to previous messageGo to next message
kish_ulike
Messages: 30
Registered: June 2008
Location: chennai
Member

Hi
I think this is your requirement
   /* Formatted on 2009/10/26 15:03 (Formatter Plus v4.8.8) */
SELECT *
  FROM table_name
 WHERE ID IN (SELECT   ID
                  FROM table_name
                HAVING COUNT (ID) > 1
              GROUP BY ID)

if it is not tell ..will try other Smile


[Mod-Edit: Frank added [code]-tags to improve readability]

[Updated on: Mon, 26 October 2009 04:40] by Moderator

Report message to a moderator

Re: Need help with a SQL Query [message #427877 is a reply to message #427860] Mon, 26 October 2009 05:05 Go to previous message
Michel Cadot
Messages: 64102
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Thanks to answer this forum.
Please read OraFAQ Forum Guide.

Regards
Michel
Previous Topic: Shows null on update & Update not work for select statement (merged)
Next Topic: Grant select on all tables of schema [Merged]
Goto Forum:
  


Current Time: Fri Dec 02 14:30:55 CST 2016

Total time taken to generate the page: 0.30746 seconds