How do I avoid duplicate entries when using multiple tables

I'm having trouble with multiple tables. How do I get  certain lines from duplicating. I attached a spreadsheet with items highlighted in yellow of what I would like to see. The un-highlighted areas are duplicate infotmation. I have trouble understanding what order tables should be selected and what joins to use. Thanks for any help you may give.
select RMA.DC_ID, RMA.RMA_BR_ID||''|| RMA.RMA_ID,  RMA.RMA_LINE_NBR, RMA.PART_ID, RMA.CUST_PART_ID, RMA.PART_DESCRIPTION, RMA.RMA_ORIG_QTY, RMA.RMA_OPEN_QTY, RMA.RMA_RECEIVED_QTY, RMA.RMA_REASON_CODE, RMA.RMA_LINE_TYPE, RMA.VENDOR_IND, RMA.RTC_REASON_CODE, RMA1.RMA_CREATE_DATE, RMA1.RMA_STATUS, RMA1.CUST_ID, RMA1.CUST_NAME, RMA1.END_USER_RMA_ID, RMA2.DESCRIPTION_NBR, RMA2.DESCRIPTION
from CSI.RMA_LINE RMA, CSI.RMA_HEADER RMA1, CSI.RMA_DESCRIPTION RMA2
where RMA.RMA_BR_ID = RMA1.RMA_BR_ID
	and RMA.RMA_ID = RMA1.RMA_ID
	and RMA.DC_ID = RMA1.DC_ID
	and RMA1.DC_ID = RMA2.DC_ID
	and RMA1.RMA_BR_ID = RMA2.RMA_BR_ID
	and RMA1.RMA_ID = RMA2.RMA_ID
	and RMA.RMA_LINE_NBR = RMA2.RMA_LINE_NBR
	and (RMA1.CUST_ID in ('60118296', '60216776', '60305816', '60588621', '60691030'))
                and RMA1.RMA_CREATE_DATE >= @VARIABLE ('BEGINNING DATE')
                and RMA1.RMA_CREATE_DATE <= @VARIABLE ('ENDING DATE')

Open in new window

RMA-Report.xls
Jbancr1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SharathData EngineerCommented:
You can use GRIUP BY. You have many columns in your SELECT statement but very few in the attached xls. Can you bit elobarate on sample data in your three tables and desired output?
0
germano_ptCommented:
First, avoid cartesian joins (represented by the comma)... They cross all records from table A with all records from table B... which will them be crossed with all records from table C, and so on...

You them filter-out the invalid "crossed records" in the WHERE clause, but it is very inefficient and prone to errors.

You should join with the JOIN keyword, indicating the join condition with the ON keyword (in fact, you'll be performing an INNER JOIN... read more in http://en.wikipedia.org/wiki/Join_(SQL) ).

Now, for the column data you don't want, notice that all the rows are valid distinct records. If you want to hide the duplicate column's values, you should do it somewhere else with code, not in the SQL statement.
SELECT
  RMA.DC_ID, RMA.RMA_BR_ID||''|| RMA.RMA_ID,  RMA.RMA_LINE_NBR, RMA.PART_ID, RMA.CUST_PART_ID, RMA.PART_DESCRIPTION, RMA.RMA_ORIG_QTY, RMA.RMA_OPEN_QTY, RMA.RMA_RECEIVED_QTY, RMA.RMA_REASON_CODE, RMA.RMA_LINE_TYPE, RMA.VENDOR_IND, RMA.RTC_REASON_CODE, RMA1.RMA_CREATE_DATE, RMA1.RMA_STATUS, RMA1.CUST_ID, RMA1.CUST_NAME, RMA1.END_USER_RMA_ID, RMA2.DESCRIPTION_NBR, RMA2.DESCRIPTION
 
FROM CSI.RMA_LINE RMA
 
 JOIN CSI.RMA_HEADER RMA1
  ON RMA.RMA_ID = RMA1.RMA_ID
   AND RMA.RMA_BR_ID = RMA1.RMA_BR_ID
   AND RMA.DC_ID = RMA1.DC_ID
 
 JOIN CSI.RMA_DESCRIPTION RMA2
  ON RMA1.DC_ID = RMA2.DC_ID
   AND RMA1.RMA_BR_ID = RMA2.RMA_BR_ID
   AND RMA1.RMA_ID = RMA2.RMA_ID
   AND RMA.RMA_LINE_NBR = RMA2.RMA_LINE_NBR
 
WHERE (RMA1.CUST_ID IN ('60118296', '60216776', '60305816', '60588621', '60691030'))
  AND RMA1.RMA_CREATE_DATE >= @VARIABLE ('BEGINNING DATE')
  AND RMA1.RMA_CREATE_DATE <= @VARIABLE ('ENDING DATE')

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.