I have a table where I want to combine two separate rows into one row. This is a product catalog that is storing information on separate rows. Here is the sample data and the expected results.
Table name: ProductCatalog
Product_ID | Action | Date
-----------------------------------------
0001 | Added | 12/11/1983
0001 | Removed | 01/01/2003
0002 | Added | 12/11/1983
Expected result:
Product_ID | Added | Removed
========================================
0001 | 12/11/1983 | 01/01/2003
0002 | 12/11/1983 | null
I have tried joining on Product_ID
to get Added
and Removed
dates to be side by side in a new table or view but I don't get the desire results. I am not using MAX(column)
since I don't get the desire results or maybe I am grouping wrong.
I think the easiest way is conditional aggregation:
You can also do this using
pivot
.