Solved

Oracle Query Help

Posted on 2014-03-12
4
215 Views
Last Modified: 2014-03-12
I have a query below...each table has the common element of Document_id, however the LINE_ITEMS_TABLE can have multiple rows in it.  As such my results set is coming back larger than expected.  How can have the query just pull one row from the LINE_ITEMS_TABLE?

SELECT <LIST Of VALUES>
FROM WORKFLOW_TABLE A,
  HEADER_TABLE B,
  LINE_ITEMS_TABLE C
WHERE A.QUEUE = 1
AND A.USER = 'MSMITH'
AND B.ORGID     = '123'
AND A.DOCUMENT_ID = B.DOCUMENT_ID
AND C.COMPANY    = '01'
AND C.DOCUMENT_ID  = A.DOCUMENT_ID
0
Comment
Question by:jmpatton
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
David earned 500 total points
ID: 39924435
try adding AND ROWNUM = 1
0
 

Author Comment

by:jmpatton
ID: 39924456
I tried that and it only returned 1 row over all.  What I currently have in the data base is a row in the header table, a row in the workflow table, and then two rows in the line_items_table.

When I join them all up like below, it returns two records because there are two records in the line items table.  In a live setting there will be hundreds of header records each with a corresponding workflow record and multiple line items for each.

SELECT A.INVOICE_NUMBER, B.WORKFLOW_QUEUE, C.COMPANY FROM WORKFLOW_TABLE A,
  HEADER_TABLE B,
  LINE_ITEMS_TABLE C
WHERE A.QUEUE = 1
AND A.USER = 'MSMITH'
AND B.ORGID     = '123'
AND A.DOCUMENT_ID = B.DOCUMENT_ID
AND C.COMPANY    = '01'
AND C.DOCUMENT_ID  = A.DOCUMENT_ID
0
 

Author Comment

by:jmpatton
ID: 39924499
I think I figured it out.  The document id in the header table was duplicated.

Thanks for your help
0
 
LVL 23

Expert Comment

by:David
ID: 39924630
Best kind of solution, where there is effort and learning.  You're welcome.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

895 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now