如何指定何时连接到具有相同主键名称的表?
select request_id, request_created_date, request_complaint_type, request_descriptor, request_ferry_terminal
from nyc311_requests
join nyc311_locations_ferries on request_id=request_id
where request_ferry_direction = 'Manhattan Bound'
order by request_id
我有这段代码,当我尝试执行时,它说每次提到request_id时,它都是一个不明确的列。如何指定何时连接到具有相同主键名称的表?
回答:
你需要看到该表是从的,请注意我已经添加了表名到REQUEST_ID
select nyc311_requests.request_id, request_created_date, request_complaint_type, request_descriptor, request_ferry_terminal
from nyc311_requests
join nyc311_locations_ferries on nyc311_requests.request_id=nyc311_locations_ferries.request_id
where request_ferry_direction = 'Manhattan Bound'
order by request_id
,你也可以给表的别名
select r.request_id, request_created_date, request_complaint_type, request_descriptor, request_ferry_terminal
from nyc311_requests r
join nyc311_locations_ferries lf on r.request_id=lf.request_id
where request_ferry_direction = 'Manhattan Bound'
order by request_id
回答:
你必须给你的表别名。
select A.request_id, request_created_date, request_complaint_type, request_descriptor, request_ferry_terminal
from nyc311_requests A
join nyc311_locations_ferries B on A.request_id = B.request_id
where request_ferry_direction = 'Manhattan Bound'
order by request_id
你必须指定出现两个表中的字段中的别名,但一旦你知道如何做到这一点是非常简单的。
以上是 如何指定何时连接到具有相同主键名称的表? 的全部内容, 来源链接: utcz.com/qa/266902.html