0

The TableC and TableB have multiple records, I want select multiple records from TableB and one record from TableC which is working in SQL Server. But actual requirement in Oracle database where it's not working. Please help to convert below SQL Server query to Oracle.

Select 
     Data-A,
     Data-B,
    (Select Top 1 DATA-C from
     TableC Where TableC.SourcePtr=Tabbleb.Rkey order by Step Desc) as Data-C
From TableA,
     TableB
Where TableA.Source_PTR =TableB.Rkey 
5

1 Answer 1

2

You can use ROWNUM:

Select 
     Data-A,
     Data-B,
     (Select * from (
        (
            Select data-C from TableC 
            Where TableC.SourcePtr=Tabbleb.Rkey order by Step Desc
        )
      where rownum = 1 ) as Data-C
From TableA,
     TableB
Where TableA.Source_PTR =TableB.Rkey 

or you can use FETCH NEXT N ROWS ONLY:

Select 
     Data-A,
     Data-B,
     (Select DATA-C from TableC 
      Where TableC.SourcePtr=Tabbleb.Rkey order by Step Desc
      FETCH NEXT 1 ROWS ONLY) as Data-C
From TableA,
     TableB
Where TableA.Source_PTR =TableB.Rkey 
Sign up to request clarification or add additional context in comments.

1 Comment

Rezu :) Thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.