?
Solved

Selecting the first record in a subquery in Oracle

Posted on 2014-04-10
2
Medium Priority
?
2,001 Views
Last Modified: 2014-04-10
Experts,

I want to read a table that has multiple records with the same ID number to get a value.  Is there a way in Oracle to select the first record only that meets the criteria?

I would like to use a subquery and I don't want to get the error multiple rows returned.
0
Comment
Question by:morinia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Assisted Solution

by:Wasim Akram Shaik
Wasim Akram Shaik earned 1000 total points
ID: 39992273
I think you are talking to select distinct records from a table which has duplicate values

select * FROM your_table
WHERE rowid not in
(SELECT MIN(rowid)
FROM your_table
GROUP BY column1, column2, column3)

where column1,column2,column3 are the duplicate columns, this will list you non-duplicate rows
0
 
LVL 15

Accepted Solution

by:
Devinder Singh Virdi earned 1000 total points
ID: 39992283
Another method

select * from
(
  select * from table where some_condition=true
) where rownum < 2;

>>I would like to use a subquery and I don't want to get the error multiple rows returned.

I am assuming you are trying to use this as inline view.
ex.
select a, b, (select statement) X from table etc
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question