简体   繁体   中英

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.

The two tables I need are:

  • PEOPLE with columns ID, NAME.
  • COMPANY with columns ID, EMPLOYEE, SUPERVISOR

Can I link the EMPLOYEE with the PEOPLE.ID and SUPERVISOR again with PEOPLE.ID ?

Does it make sense? I am asking because Access created a duplicate PEOPLE_1 table to link the second column.

Thanks,

Yes. The way Access made it, works. You need the PEOPLE table twice, so you can reference two different records (the employee and the supervisor) at the same time.

If you want, you can also set an alias for both PEOPLE tables. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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