简体   繁体   中英

Access SQL Lookup - Dropdown Columns

I have looked for a similar issue with no luck. Maybe I don't know the right term to search for.

This seems so simple, but I just can't get it after spending many hours trying different approaches.

I have a dropdown to select contracts which shows some ids for related fields. How can I get those IDs to show the value of another column.

SELECT tbl_contracts.ID, tbl_contracts.contract_name, tbl_contracts.firm_id, tbl_contracts.agency_id
FROM tbl_contracts;

image of dropdown

I would like the IDs shown for agency_id and firm_id to list the company_name from their respective table "tbl_firm_agencies" where the tbl_contracts looks them up from. I've tried INNER JOINS but when I do, I can only line items to show when both agency AND firm exist, so my dropdown get cut off quite a bit.

Simply LEFT JOIN to those lookup tables as opposed to INNER JOIN . Adjust table and field names to actual ones in query below. Also, the parentheses are required in MS Access SQL.

SELECT c.ID, c.contract_name, f.firm_name, a.agency_name
FROM (tbl_contracts c
LEFT JOIN tbl_firms f
   ON c.firm_id = f.firm_name)
LEFT JOIN tbl_agencies a
   ON c.agency_id = a.agency_name;

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