dbTalk Databases Forums  

return column in select based on another column value

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss return column in select based on another column value in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
kishjeff
 
Posts: n/a

Default return column in select based on another column value - 12-03-2007 , 12:58 PM






Hi.
This is sort of like asking how to do a comma operator in sql on
Oracle.
I'm not sure how to approach asking the question, or even search for
it except
for posting the question here.

If I have this table (2 cols, 1st row is col name):

col1 col2
type1 def5
type2 abc4
type1 null
type3 null

I'd like to have a select statement return this:

colz coly
null def5 because it is type1 return col2 as 2nd col
abc4 null because it is type2 return col2 as 1st col
null null
null null

in other words I'd like to have a certain column in the result set
return:
col2 in coly or col2 in colz based on value of col1

What is the best way to do this with an sql query, or is it even
possible?
I'm targeting Oracle 9i onwards
thanks for even a hint.. I can look up the details.


Reply With Quote
  #2  
Old   
DA Morgan
 
Posts: n/a

Default Re: return column in select based on another column value - 12-03-2007 , 01:05 PM






kishjeff wrote:
Quote:
Hi.
This is sort of like asking how to do a comma operator in sql on
Oracle.
I'm not sure how to approach asking the question, or even search for
it except
for posting the question here.

If I have this table (2 cols, 1st row is col name):

col1 col2
type1 def5
type2 abc4
type1 null
type3 null

I'd like to have a select statement return this:

colz coly
null def5 because it is type1 return col2 as 2nd col
abc4 null because it is type2 return col2 as 1st col
null null
null null

in other words I'd like to have a certain column in the result set
return:
col2 in coly or col2 in colz based on value of col1

What is the best way to do this with an sql query, or is it even
possible?
I'm targeting Oracle 9i onwards
thanks for even a hint.. I can look up the details.
Making a wild stab at what you are asking use DECODE or CASE
http://www.psoug.org/reference/decode_case.html
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #3  
Old   
Ed Prochak
 
Posts: n/a

Default Re: return column in select based on another column value - 12-03-2007 , 01:14 PM



On Dec 3, 1:58 pm, kishjeff <kishjj... (AT) charter (DOT) net> wrote:
Quote:
Hi.
This is sort of like asking how to do a comma operator in sql on
Oracle.
I'm not sure how to approach asking the question, or even search for
it except
for posting the question here.

If I have this table (2 cols, 1st row is col name):

col1 col2
type1 def5
type2 abc4
type1 null
type3 null

I'd like to have a select statement return this:

colz coly
null def5 because it is type1 return col2 as 2nd col
abc4 null because it is type2 return col2 as 1st col
null null
null null

in other words I'd like to have a certain column in the result set
return:
col2 in coly or col2 in colz based on value of col1

What is the best way to do this with an sql query, or is it even
possible?
I'm targeting Oracle 9i onwards
thanks for even a hint.. I can look up the details.
look up the CASE clause
Ed


Reply With Quote
  #4  
Old   
kishjeff
 
Posts: n/a

Default Re: return column in select based on another column value - 12-03-2007 , 01:32 PM



On Dec 3, 2:14 pm, Ed Prochak <edproc... (AT) gmail (DOT) com> wrote:
Quote:
On Dec 3, 1:58 pm, kishjeff <kishjj... (AT) charter (DOT) net> wrote:





Hi.
This is sort of like asking how to do a comma operator in sql on
Oracle.
I'm not sure how to approach asking the question, or even search for
it except
for posting the question here.

If I have this table (2 cols, 1st row is col name):

col1 col2
type1 def5
type2 abc4
type1 null
type3 null

I'd like to have a select statement return this:

colz coly
null def5 because it is type1 return col2 as 2nd col
abc4 null because it is type2 return col2 as 1st col
null null
null null

in other words I'd like to have a certain column in the result set
return:
col2 in coly or col2 in colz based on value of col1

What is the best way to do this with an sql query, or is it even
possible?
I'm targeting Oracle 9i onwards
thanks for even a hint.. I can look up the details.

look up the CASE clause
Ed- Hide quoted text -

- Show quoted text -
thanks to both of you. Decode looks like it works.. let me check out
the case clause now to see which has a better fit.
regards
Jeff


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.