Skip to content
Advertisement

MySQL self join but in the same row

I have this table:

date sku note
11/12 123 note
11/13 123 note
11/12 456 note
11/13 456 note
11/12 789 note
11/13 789 note

(Note is random) And I want the result to return this:

date sku note sku note sku note
11/12 123 note 456 note 789 note
11/13 123 note 456 note 789 note

I tried self join

but this is what I got:

date sku note sku
11/12 123 note 456
11/12 123 note 789
11/13 123 note 456
11/13 123 note 789

Advertisement

Answer

Calculate a row_number, then pivot.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement