Solved

sql server self join

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

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.
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

791 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