Solved

sql server self join

Posted on 2014-01-13
1
199 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now