Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle Query Help

Posted on 2014-03-12
4
Medium Priority
?
221 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

886 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