﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Joining Table to Itself / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 21:23:34 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Joining Table to Itself</title><link>http://www.sqlservercentral.com/Forums/Topic1405607-391-1.aspx</link><description>No problem. I would suggest changing to a left join instead. If you use an inner join and there is no supervisor you won't get the employee information either.</description><pubDate>Fri, 11 Jan 2013 12:16:19 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Joining Table to Itself</title><link>http://www.sqlservercentral.com/Forums/Topic1405607-391-1.aspx</link><description>Actually, I figured it out:-D I just needed to add this to my SELECT statement;SUP.firstname_vc as [Suprvisor First Name],SUP.lastname_vc as [Suprvisor Last Name] Since I was getting the name from the firstname_vc, lastname_vc of the same table. Remember, A staff person could be a Supervisor as well.I then added this join; inner join ar.staffmaster as SUP on STM.birthcountry_vc = SUP.staffcode_cAnd it worked beautifully. Thanks for your reply though. I am a newbie.</description><pubDate>Fri, 11 Jan 2013 11:14:27 GMT</pubDate><dc:creator>markafisher92</dc:creator></item><item><title>RE: Joining Table to Itself</title><link>http://www.sqlservercentral.com/Forums/Topic1405607-391-1.aspx</link><description>This is likely VERY close.[code]SELECT STM.staffcode_c as [Staff Code],STM.firstname_vc as [First Name],STM.lastname_vc as [Last Name],PC.description_vc as [Program],STM.department_vc as [Title]STM.birthcountry_vc as [Spervisor],supervisor.firstname_vc as [Supervisor First Name],supervisor.lastname_vc as [Supervisor Last Name]FROM ar.staffmaster as STMinner join ar.programcodes as PC on STM.division_vc = PC.code_cinner join cd.rhd_incidents as I on I.staff_c = STM.birthcountry_vc or I.staff_c = STM.staffcode_cleft join ar.staffmaster supervisor on supervisor.staffcode_c = STM.[Whatever Field is the Supervisor staffcode_c][/code]I can't tell what column in staffmaster indicates the value of the supervisor. Your query says it is birthcountry_vc but somehow I doubt that is right. :-P</description><pubDate>Thu, 10 Jan 2013 13:26:38 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Joining Table to Itself</title><link>http://www.sqlservercentral.com/Forums/Topic1405607-391-1.aspx</link><description>Hi and welcome to SSC!!! We need some details before we can offer much assistance here. We would like to see ddl (create table statements), sample data (insert statements) and desired output based on the sample data. You can find details about how to post this information and how to put it together by taking a look at the first link in my signature.</description><pubDate>Thu, 10 Jan 2013 13:22:20 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>Joining Table to Itself</title><link>http://www.sqlservercentral.com/Forums/Topic1405607-391-1.aspx</link><description>I need to return the firstname_vc, and lastname_vc from the ar.staffmaster table of the Supervisors. A staff member in this table  may also be a supervisor. The birthcountry_vc is the staffcode_c of the staff person who is their supervisor. I need to show the first and last name of the supervisor in a report. How do I query the same table in order to do this? Like I said, the birthcountry_vc is the staffcode_c of the staff person who is their supervisor.  I tried this, but I cant get the supervisors first and last name.SELECT STM.staffcode_c as [Staff Code],       STM.firstname_vc as [First Name],       STM.lastname_vc as [Last Name],       PC.description_vc as [Program],       STM.department_vc as [Title]STM.birthcountry_vc as [Spervisor]FROM ar.staffmaster as STM       inner join ar.programcodes as PC on STM.division_vc = PC.code_c       inner join cd.rhd_incidents as I on I.staff_c = STM.birthcountry_vc or I.staff_c = STM.staffcode_cIt returns this;   		Staff Code  First Name  Last Name Program    Title       Supervisor   	             frye 	    Audra              Frye        THR	NULL	bcaryapoolson     April	             Poolson	TTp	NULL	NULLbcary    	    Bridget	Cary	OOP	Couns     NULLmpardue	    Melissa	Pardue	FRD	NULL	NULLAs you can see, "bcary" is Audra Fryes' Supervisor, but "bcary is also a Staff member." How do I return bcarys first name for, should I join the table to itself??</description><pubDate>Thu, 10 Jan 2013 12:46:17 GMT</pubDate><dc:creator>markafisher92</dc:creator></item></channel></rss>