File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Oracle/OAS and the fly likes Oracle PL/SQL query Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Reply Bookmark "Oracle PL/SQL query" Watch "Oracle PL/SQL query" New topic
Author

Oracle PL/SQL query

Muthu Lakshmi
Greenhorn

Joined: Mar 07, 2006
Posts: 6
Hi all,
I find difficulty in writing a single query for the following scenario.
Please help.

I have a table as follows:

TABLE1
MapId SubId Name
1 0 A
2 0 B
3 1 c
4 0 D
4 1 D
4 2 D
5 2 E
6 1 F

Using a query I have to fetch 'Mapid' and 'Name' from TABLE1 such that the 'Mapid' should no be duplicated. Here 'Mapid' and 'Subid' is the PrimaryKeys.
The result of the query should be:
MapId SubId Name
1 0 A
2 0 B
3 1 c
4 0 D
5 2 E
6 1 F

I've tried so many times.but I couldn get.
Please help.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17225
    
    1

Well, you issue is that the subid is different when you have multiple rows. What are some possible ways to help stop that aggregation, er agravation?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I'm not sure whether it will work but did you try with distinct clause ?

SELECT DISTINCT MapId, Name FROM Table1.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17225
    
    1

Originally posted by Srinivasa Raghavan:
I'm not sure whether it will work but did you try with distinct clause ?

SELECT DISTINCT MapId, Name FROM Table1.


That won't work because it is missing the subid in the resultset, and when you add that then you will not get the results you want.

Also, this looks like homework, so we want to give really good hints to help out, but not give the answer completely away. Like my hint really does give it a way in a MIN type of way.

Mark
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Oracle PL/SQL query
 
Similar Threads
New Mock Exam questions...
Take the Dr. Phil Test
how to create a boolean truth table
SCBCD Mock Questions, batch #3
Question on switch