简体   繁体   English

有没有办法让表中的两列链接到同一个参考表?

[英]Is there a way to have two columns in a table having linked to the same reference table?

New to designing databases.设计数据库的新手。 I currently try to create a database in MS Access.我目前尝试在 MS Access 中创建一个数据库。

The two tables I need are:我需要的两张表是:

  • PEOPLE with columns ID, NAME.列 ID、 PEOPLE的人。
  • COMPANY with columns ID, EMPLOYEE, SUPERVISOR具有列 ID、EMPLOYEE、SUPERVISOR 的COMPANY

Can I link the EMPLOYEE with the PEOPLE.ID and SUPERVISOR again with PEOPLE.ID ?我可以将EMPLOYEEPEOPLE.IDSUPERVISOR再次与PEOPLE.ID吗?

Does it make sense?是否有意义? I am asking because Access created a duplicate PEOPLE_1 table to link the second column.我问是因为 Access 创建了一个重复的PEOPLE_1表来链接第二列。

Thanks,谢谢,

Yes.是的。 The way Access made it, works. Access 的方式很有效。 You need the PEOPLE table twice, so you can reference two different records (the employee and the supervisor) at the same time.您需要两次 PEOPLE 表,因此您可以同时引用两条不同的记录(员工和主管)。

If you want, you can also set an alias for both PEOPLE tables.如果需要,您还可以为两个 PEOPLE 表设置别名。 Example:例子:

SELECT COMPANY.ID, emp.NAME, sup.NAME
FROM COMPANY LEFT JOIN PEOPLE AS emp ON COMPANY.EMPLOYEE = emp.ID
LEFT JOIN PEOPLE AS sup ON COMPANY.SUPERVISOR = sup.ID

(I didn't use Access for quite a long time. Maybe you have to put brackets around one of the join statements to make it work) (我很长时间没有使用 Access。也许您必须在其中一个连接语句周围加上方括号才能使其工作)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM