简体   繁体   English

如何交叉引用具有名字+姓氏字段的两个表

[英]How to cross reference two tables that have FirstName + LastName fields

I want to match two tables that both have first + last name fields. 我想匹配两个都有名字和姓氏字段的表。 I would like to return the records that match each person's first + last name combination. 我想返回与每个人的名字和姓氏组合匹配的记录。

Table 1 fields: 表1字段:

id|firstname|lastname|position|

Table 2 fields: 表2字段:

firstname|lastname|datehired|department|deptcode|

You can join on multiple columns: 您可以加入多个列:

SELECT t1.id, t1.firstname, t1.lastname, t1.position, 
       t2.datehired, t2.department, t2.deptcode
FROM Table1 t1 INNER JOIN Table2 t2
    ON t1.firstname = t2.firstname
   AND t1.lastname  = t2.lastname

How about: 怎么样:

Select FirstName, LastName From Table1

Intersect

Select Firstname, LastName From Table2

You need to include both conditions in your join 您需要在加入时同时包含两个条件

SELECT *  
FROM Table1  
JOIN Table2 ON Table1.firstname = Table2.firstname AND Table1.lastname = Table2.lastname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置一个输出参数,它是两个字段的组合,例如fullname = firstname + lastname? - How to set an output parameter that is the combination of two fields, e.g., fullname=firstname+lastname? 如何在mongodb中搜索名字和姓氏 - How to search firstname and lastname in mongodb SQL如何交叉引用两个不相关的表 - SQL how to cross reference two unrelated tables 如何对名字、姓氏进行 SQL 搜索查询 - How to make SQL search query for firstname, lastname 如何在SQL中组合firstname和lastname并使用LIKE进行搜索 - how to combine firstname and lastname in SQL and search with LIKE 两张表之间的交叉引用 - Cross reference between two tables 当可能有中间名首字母时,如何从“名字的姓氏”中查询“名字的姓氏”? - How to query “LastName, FirstName” from “FirstName LastName” when there may be middle initials? 如何在Postgres中将表列数据从'LastName,FirstName'转换为'FirstName LastName' - How do I convert table column data from 'LastName, FirstName' to 'FirstName LastName' in Postgres 将姓氏,名字更改为姓氏,名字首字母 - Changing LastName,FirstName to LastName,FirstInitial 如何使用Google BigQuery SQL交叉引用两个大数据表? - How To Cross Reference Two Big Data Tables With Google BigQuery SQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM