Home » SQL & PL/SQL » SQL & PL/SQL » can someone suggest a select for this
can someone suggest a select for this [message #274156] Sun, 14 October 2007 15:21 Go to next message
qqqwww
Messages: 1
Registered: October 2007
Junior Member
Hi,
i have a table like this:
table name | code | name |

i need to select all records with code 1 and show them on column named "col 1".
and alsd select all records with code 2 and show them on column named "col 2 ".

can someone suggest a select for this ?

thanks
Re: can someone suggest a select for this [message #274158 is a reply to message #274156] Sun, 14 October 2007 15:34 Go to previous message
Littlefoot
Messages: 21821
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
You might use CODE or DECODE to do that; here's a CODE example:
SELECT CASE 
         WHEN code = 1 THEN table_name ||' - '|| name
         ELSE NULL
       END col_1,
       CASE
         WHEN code = 2 THEN table_name ||' - '|| name
         ELSE NULL
       END col_2
FROM T_CODE;
Do the same using the DECODE function yourself.
Previous Topic: Querying on hierarchical tables
Next Topic: exact fetch returns more than requested number of rows
Goto Forum:
  


Current Time: Mon Nov 11 02:27:44 CST 2024