question

Bhasker avatar image
Bhasker asked

How to combine two rows of same table, with out any common data

Need a single query to combine two rows of same table Actual Table Code-------Store---------Sect 1------------Null------------A 2------------abc------------Null 3------------XYZ-------------Null 4------------Null-------------B Desired O/P Code-------Store---------Sect 2-----------abc-------------A 3-----------XYZ-------------B
tabletablescommon-table-expressionactual-rows
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sule avatar image Sule commented ·
How do you know which two rows need to be combined? Why this combination is not correct?: 2-----abc-----B 3-----XYZ-----A
2 Likes 2 ·

1 Answer

·
Shambhu.Kumar avatar image
Shambhu.Kumar answered
SELECT A.Code, A.Store, B.Sect FROM (SELECT Code , Store , Sect , ROW_NUMBER() OVER (PARTITION BY 1 ORDER BY Code)AS ROWNUM FROM TABLE_NAME WHERE Store IS NOT NULL)A INNER JOIN (SELECT Code , Store , Sect , ROW_NUMBER() OVER (PARTITION BY 1 ORDER BY Code)AS ROWNUM FROM TABLE_NAME WHERE Sect IS NOT NULL)A ON A.ROWNUM = B.ROWNUM
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.