我确信这可以通过加入来完成,但在加入方面我并不那么无知:
假设我有 3 张桌子。表一是分支机构,表二是县,表三是州
表一:
branchid - Unique record id
siteCode - Unique identifier for the branch
address1 - Street address #1
address2 - Street address #2
cityName - City Name
county_ID - record ID from county table
state_ID - record ID from state table
表二:
countyid - Unique record ID
countyName - County Name
表三
stateid - Unique record ID
stateShortName - State name two letter abbreviation
stateLongName - Full state name
使用对分支的普通查询,我得到了一个记录,其中包含州和县表中关联记录的编号。
我想做一个查询,从表一中的记录返回信息,并将记录 id 替换为正确的县名和州名
那有意义吗?
例子:
正常查询返回:
branchid - 1
siteCode - CA001
address1 - 123 Main Street
address2 - Suite #201
cityName - San Diego
county_ID - 234
state_ID - 2
正确查询:
branchid - 1
siteCode - CA001
address1 - 123 Main Street
address2 - Suite #201
cityName - San Diego
county_ID - Sand Diego County
state_ID - CA