I need help isolating multiple entries in order.

Column A Column B Column C
100a 1000 ABC
100a 1000 DEF
200b 2000 GHI
300c 3000 JKL
300c 3000 MNO

There are duplicates in Column A (which has a 1:1 relationship to column b). However, they have a 1:many with column C. Column C will always be unique.

I need to create a report that returns:

Column A Column B Column C Column D
100 1000 ABC DEF
200 2000 GHI
300 3000 JKL MNO

Any help? I am pretty new to SQL so this is giving me a lot of trouble figuring it out.

I am at a loss where to start. I tried to declare a variable, but not sure where to start with it.

1

There are 1 best solutions below

0
Renat On

If it's no more than 2 values in Column C for Column A + Column B key, then a query below would work. It will not work for 3 or more values

SELECT 
  Column_A, 
  Column_B, 
  MIN(Column_C) AS "Column C", 
  CASE WHEN MIN(Column_C) <> MAX(Column_C) 
     THEN MAX(Column_C)
     ELSE ''
  END AS "Column D"
FROM some_table
GROUP BY Column_A, Column_B
Column_A Column_B Column C Column D
100a 1000 ABC DEF
200b 2000 GHI
300c 3000 JKL MNO

(live demo: dbfiddle )