Solved

sql server self join

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL BCP Extra Lines Between Records 2 28
Substring works but need to tweak it 14 31
Parsing this XML works but the other one doesn't 9 27
How can I find this data? 3 24
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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