Multiple rows into Single row

Database
Enthusiast

Multiple rows into Single row

Hi Team,

I have a requirement like below.

Col1 

ABC

DEF

and if my COL1 has any of ABC or DEF then it should make another entry say 'XYZ' like below.

COL1

ABC

DEF

XYZ.

When i use a case statement like below.

INSERT INTO TABLE A SELECT 'XYZ' FROM TABLE A WHERE COL1 = 'ABC' OR COL1='DEF' . But this statement inserts 2 rows as there are 2 matches. How can i narrow it down to just one 'XYZ'.

Thanks in advance.

-- AsCharan

Tags (3)
1 REPLY
Enthusiast

Re: Multiple rows into Single row

This should work

INSERT INTO TABLE A SELECT DISTINCT('XYZ') FROM TABLE A WHERE COL1 = 'ABC' OR COL1='DEF'

-Samir