Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Merging columns in SQL query based on the certain criteria

$
0
0

Hi,

I find query below:

SELECT AL1.BILL_NO as "Bill No", AL3.MAIN_TYPE as "Main Type", AL3.BILL_NO as "Bill No",
AL3.SUB_TYPE as "Sub Type", AL3.AMOUNT as "Amount", AL2.PAY_ID as "Pay ID"

FROM TABLE1 AL1, TABLE2 AL2, TABLE3 AL3, TABLE4 AL4, TABLE5 AL5
WHERE (AL1.BILL_NO = AL4.BILL_NO (+) AND  AL1.REF_NO = AL5.REF_NO (+) AND
AL1.BILL_NO=AL2.BILL_NO AND AL4.ID=AL3.ID)

This query is returning the duplicate records. What I want is if Bill No and MAIN TYPE is same, then it should combine SUB TYPE to avoid counting of duplicate records.

Thanks


Viewing all articles
Browse latest Browse all 23857

Trending Articles