• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Oracle PL/SQL query

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure whether it will work but did you try with distinct clause ?

SELECT DISTINCT MapId, Name FROM Table1.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic