Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: merging two rows
> for example i have two rows in this manner
>
> id name account type code
>
> 1 sunil checking x a1
> 2 sunil savings y a2
>
> can i get in this way by merging two rows
>
> id name account type code account1 type1 code 1
>
> 1 sunil checking x a1 savings y a2
>
> i tried to do self join also o think it does not work since there is
> one primary key called id
> and there is no chance of group by also
>
> thank you
> sunil
>
Is the NAME field unique? If so, then a self join as follows would work:
SELECT t1.name, t1.account,t1.type,t1.code, t2.account,t2.type,t2.code
FROM table t1, table t2
WHERE t1.name=t2.name
AND t1.account='CHECKING' and t2.account='SAVINGS';
In your case, a GROUP BY is not the correct clause for the job..based on what you have provided so far.
If the NAME field is not unique, then how do you determine which rows get "merged" with other rows?
HTH,
Brian
-- =================================================================== Brian Peasland dba_at_nospam.peasland.net http://www.peasland.net Remove the "nospam." from the email address to email me. "I can give it to you cheap, quick, and good. Now pick two out of the three" - UnknownReceived on Wed Sep 27 2006 - 08:21:33 CDT
![]() |
![]() |