Solved

sql server self join

Posted on 2014-01-13
1
201 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach 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.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

822 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