我现在一直在使用此查询,而且我很难过。我是SQL的新手,我无法弄清楚我收到错误的原因:
SELECT customer_number, first_name_initial, last_name,serve_address_1, serve_address_2, serve_city, serve_state, route_serve_zip_code, phone_number1, referral_code
FROM customer_master
INNER JOIN route_detail
ON m.customer_number=r.customer_number
WHERE (referral_code='american')
ERROR
Msg 209,Level 16,State 1,Line 1 不明确的列名称' customer_number'。 Msg 209,Level 16,State 1,Line 1 不明确的列名称' phone_number1'。
我尝试按如下方式添加列,但也没有运气。任何帮助将不胜感激!
SELECT customer_number, first_name_initial, last_name,serve_address_1, serve_address_2, serve_city, serve_state, route_serve_zip_code, phone_number1, referral_code
FROM customer_master m
INNER JOIN route_detail r
ON m.customer_number=r.customer_number
WHERE (referral_code='american')
答案 0 :(得分:5)
问题在于这一行
SELECT customer_number
您需要指定从哪个表中获取customer_number,如下所示:
SELECT r.customer_number
或
SELECT m.customer_number
所以你的最终查询看起来像这样:
SELECT r.customer_number, --or m.customer_number
first_name_initial, last_name,serve_address_1, serve_address_2, serve_city, serve_state, route_serve_zip_code, phone_number1, referral_code
FROM customer_master
INNER JOIN route_detail
ON m.customer_number=r.customer_number
WHERE (referral_code='american')