Home » SQL & PL/SQL » SQL & PL/SQL » Combine 2 columns
Combine 2 columns [message #223277] Thu, 08 March 2007 04:26 Go to next message
abis123
Messages: 31
Registered: February 2007
Member
I have an SQL statement shown below. What I want to do is combine 2 columns. That being MAIN_CATEGORY and SUB_CATEGORY with a > in the middle if possible.

SELECT J1.JOB_NAME AS MAIN_CATEGORY, J2.JOB_NAME AS SUB_CATEGORY,
J2.JOB_ID AS JOB_ID FROM HI.JOB J1, HI.JOB J2 WHERE J1.JOB_ID = J2.RELATING_JOB AND J1.JOB_ID != 0
Re: Combine 2 columns [message #223278 is a reply to message #223277] Thu, 08 March 2007 04:30 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
hi,


use the concatenating operation ||'>'||.



regards,
Re: Combine 2 columns [message #223309 is a reply to message #223277] Thu, 08 March 2007 07:33 Go to previous messageGo to next message
martijn
Messages: 283
Registered: December 2006
Location: Netherlands
Senior Member
SELECT J1.JOB_NAME||'>'||J2.JOB_NAME,
       J2.JOB_ID AS JOB_ID 
FROM   HI.JOB J1, 
       HI.JOB J2 
WHERE  J1.JOB_ID = J2.RELATING_JOB 
       AND J1.JOB_ID != 0
Re: Combine 2 columns [message #223311 is a reply to message #223309] Thu, 08 March 2007 07:40 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
And if you're reluctant to use the double pipe, you can always look at


MHE
Re: Combine 2 columns [message #223319 is a reply to message #223311] Thu, 08 March 2007 07:53 Go to previous messageGo to next message
martijn
Messages: 283
Registered: December 2006
Location: Netherlands
Senior Member
Maaher,

Just out of curiosity: why should I be reluctant to use ||

(
I ask this because I working as a DBA not to long now, and always wonder why people will or will not user a certain syntax
)
Re: Combine 2 columns [message #223321 is a reply to message #223319] Thu, 08 March 2007 07:57 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Laughing Nah, I was just looking at the thread and I recalled the CONCAT function, which I never used myself. I was wondering the exact same thing as you: why would one use CONCAT since it only accepts two parameters...

MHE
Re: Combine 2 columns [message #223322 is a reply to message #223321] Thu, 08 March 2007 07:59 Go to previous messageGo to next message
martijn
Messages: 283
Registered: December 2006
Location: Netherlands
Senior Member
hahahahaha

tnx.

Re: Combine 2 columns [message #223325 is a reply to message #223322] Thu, 08 March 2007 08:03 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Hey, apparently it does have a purpose: system independence. Look at this thread on OTN.

MHE
Re: Combine 2 columns [message #223333 is a reply to message #223325] Thu, 08 March 2007 08:14 Go to previous messageGo to next message
martijn
Messages: 283
Registered: December 2006
Location: Netherlands
Senior Member
I just read it.
I guess it makes a point.

However.... I just started reading a book by Tom Kyte in which he tells that platform independence is quite hard to achive.

But anyway....I stick with ||
Re: Combine 2 columns [message #223336 is a reply to message #223333] Thu, 08 March 2007 08:23 Go to previous message
abis123
Messages: 31
Registered: February 2007
Member
Really?
Previous Topic: unable to run delete/update/insert statements on a table
Next Topic: Trim extra space (merged)
Goto Forum:
  


Current Time: Fri Dec 09 00:28:35 CST 2016

Total time taken to generate the page: 0.20984 seconds