Solved

Selecting the first record in a subquery in Oracle

Posted on 2014-04-10
2
1,919 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 250 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 250 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

691 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