Sql server 2008 两个表之间的Sql查询

Sql server 2008 两个表之间的Sql查询,sql-server-2008,Sql Server 2008,我只想创建一个查询,但无法成功创建它。 我只想从两个表中获取数据,但不想创建正确的查询。 这是我的问题 this is my first table emp with id as a primary key id(primary key) name 101 A 102 B 103 C 104 D this is my second tabl

我只想创建一个查询,但无法成功创建它。 我只想从两个表中获取数据,但不想创建正确的查询。 这是我的问题

this is my first table emp with id as a primary key
id(primary key)       name
101                   A
102                   B
103                   C
104                   D

this is my second table boss with bossid as a foreign key with emp table column id
bossid(foreign key with emp table in column id)          empid
102                                                      101
103                                                      104




now i just want to create a sql query which return me a data like this
bossid    name   empid    name
102       B      101      A
103       C      104      D


In this return query 'B' and 'C' is boss name from emp table with bossid '102','103' and 'A' and 'D' is the emp name from same table emp with empid '101','104' join with bossid from bossname table and id with empname table.
提前谢谢

请参见查询:

SELECT 
  bossid, emp.name, empid, emp2.name
from boss
JOIN emp ON emp.Id = boss.bossid
join emp emp2 ON emp2.Id = boss.empid

您可以使用Left join或join

SELECT     A.bossid as bossid, B.name as name, A.empid as empid, C.name as name
FROM       boss A
LEFT JOIN  emp B
   ON         A.bossid = B.id
LEFT JOIN  emp C
    ON        A.empid = C.id

到目前为止你试过什么