Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql Query

Status
Not open for further replies.

nikol

Programmer
Apr 12, 2005
126
US
Hi ,
UID NAME PHONE
1 peter 715-987-8656
1 jill 910-987-8778
2 mike 510-758-9767
2 mott 345-987-0876

Can I make the above DB columns as
UID NAME
1 peter;715-987-8656 jill;910-987-8778
2 mike;510-758-9767 mott;345-987-0876
 
if it's only 2 values into 1, you can use a simple self-join

if it's N values into 1, see faq183-2146

r937.com | rudy.ca
 
Hi,

I got my half of the answer.
UID NAME
1 peter;715-987-8656
1 jill;910-987-8778
2 mike;510-758-9767
2 mott;345-987-0876
Now is there any way I can do the following

UID NAME
1 peter;715-987-8656 jill;910-987-8778
2 mike;510-758-9767 mott;345-987-0876


 
okay, with that exact data, you can use this:

select t1.UID
, t1.NAME + ' ' + t2.NAME as NAME
from somewhere as t1
inner
join somewhere as t2
on t1.UID = t2.UID
and t1.NAME < t2.NAME

r937.com | rudy.ca
 
Hi !! r937,
Its working.. From last 3 hrs I'm trying-trying & ofcourse I was still trying.. Thanks for the help..
I was just wondering what if a client_id has only 1 referral
like CLIENT_ID (UID 1) has only 1 referral
UID NAME
1 peter;715-987-8656
2 mike;510-758-9767 mott;345-987-0876
coz above query gives only UID's who have 2 referrals..
 
Take a look at left join in BOL

“I sense many useless updates in you... Useless updates lead to defragmentation... Defragmentation leads to downtime...Downtime leads to suffering..Defragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
how about we add more data

UID NAME
1 peter;715-987-8656
1 jill;910-987-8778
2 mike;510-758-9767
2 mott;345-987-0876
1 any1;???
1 any2;???
3 any3;???

the query above will not work...
 
your right as i've mentioned on my first post that this can only be solved by the use of SP...

though i am still skeptical that this can be solved through plain single line query...

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top