Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Inner join limit

744152May 20 2010 — edited May 20 2010
Hi all,

I have two tables as such

Event (id,name)
0, event1
1, event2
2, event3

and

Step (id, event, name, order, complete)
0,0, step1, 1, false
1,0, step2, 2, false
2,1, step1, 1, true
3,1, step2, 3, false
4,1, step3, 2, false
5,2, step1, 1, true

Basically I am trying to create a query that returns the following result
Step (id, event, name, order, complete)
0,0, step1, 1, false
4,1, step2, 2, false

The more observant out there will have noticed that the result set is a list of the next incomplete step for each event.

My problem is that I'm not too sure about the SQL involved. Here is what I have so far

SELECT S.* FROM EVENT E
INNER JOIN STEP ON S.EVENT = E.ID
WHERE S.COMPLETE = 0
ORDER BY S.ORDER ASC

This would work fine except that I get all the next incomplete steps, i.e. I get step2 and step3 returned for event2 where as I only want step2.
Is there a way to limit the inner join to just one?
Moreover, am I going about this the right way?

Any help would be much appreciated.

Thanks.
This post has been answered by Frank Kulash on May 20 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 17 2010
Added on May 20 2010
2 comments
1,828 views