连接两个表

时间:2014-05-28 13:56:32

标签: sql tsql concatenation

下面列出了两个表,表ccms_all_users和table事件,我需要将它们组合起来以获得一个输出。

TABLE CCMS_ALL_USERS
---------------------------------
| CCMS_ID | FIRST NAME |LAST NAME
---------------------------------
| 110     | JEFF       |WOOD
| 111     | MICHAEL    |JOHNSON
| 112     | HARRY      |LEE
---------------------------------

Table EVENT:
-----------------------
| MEMBER_ID | CCMS_ID |
-----------------------
| 001       | 110     |
| 002       | 111     |
| 003       | 112     |
-----------------------

我想要下面列出的所需输出,但我不确定如何使用concatenate函数以及我需要使用哪种连接语句。

我需要将实际ID转换为用户的名字和姓氏。

MY DESIRED OUTPUT
------------------------------------
| MEMBER_ID | CCMS_ID (Alias as Event Manager)                          
------------------------------------
| 001       | JEFF WOOD            |
| 002       | MICHAEL JOHSON       |
| 003       | HARRY LEE            |

我如何使用concat函数和连接在SQL中执行此操作?

3 个答案:

答案 0 :(得分:2)

 SELECT e.MEMBER_ID,
        c.[FIRST NAME] + ' ' + c.[LAST NAME] 'Event Manager'
   FROM EVENT e
        INNER JOIN CCMS_ALL_USERS c ON e.CCMS_ID = c.CCMS_ID

答案 1 :(得分:0)

尝试以下查询

 SELECT Member_ID,
        [First Name] + ' ' + [Last Name] as CCMS_ID
   FROM [EVENT] 
        JOIN [CCMS_ALL_USERS] ON [CCMS_ALL_USERS].[CCMS_ID] = [EVENT].[CCMS_ID]

答案 2 :(得分:0)

 SELECT e.MEMBER_ID,
        u.[FIRST NAME] + ' ' + u.[LAST NAME] 'Event Manager'
   FROM EVENT e
        INNER JOIN CCMS_ALL_USERS u
  USING (CCMS_ID)