Solved

sql server self join

Posted on 2014-01-13
1
211 Views
Last Modified: 2014-01-30
here is some sample data from 2 tables

Player Table

PlayerID  FirstName  LastName
1234         John            Smith
1235         Jane            Smith
1236         Joe              Doe
4756         John           Adams
4757         Jane            Adams

PlayerLink Table

PlayerId  LinkNumber
1234        55
1235        55
1236        55
4756        20
4757        20

I am trying to write a query that will look up the player id for matches in link number and return the names

Using the sample data above, the query would return the following

PlayerID   LinkNumber  FirstName LastName
1234          55                    John            Smith
1235          55                    Jane            Smith
1236          55                    Joe              Doe
4756          20                    John           Adams
4757         20                     Jane            Adams
0
Comment
Question by:johnnyg123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 39777622
This isn't really a self join, since that implies joining a table to itself.

Unless I'm completely missing something here, this should get you what you want:

select a.playerid, a.linknumber, b.firstname, b.lastname
from playerlink a 
join player b on a.playerid = b.playerid

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question