SQL 中有 2 个不明确的列名的查询错误
Query error with 2 ambiguous column names in SQL
我现在一直在使用这个查询,但遇到了困难。我是 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')
错误
消息 209,级别 16,状态 1,第 1 行
不明确的列名称 'customer_number'。
消息 209,级别 16,状态 1,第 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')
问题出在这一行
SELECT customer_number
您需要指定要从哪个 table 获取 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')
我现在一直在使用这个查询,但遇到了困难。我是 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')
错误
消息 209,级别 16,状态 1,第 1 行 不明确的列名称 'customer_number'。 消息 209,级别 16,状态 1,第 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')
问题出在这一行
SELECT customer_number
您需要指定要从哪个 table 获取 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')