SQL 多个联接返回错误“关键字 'JOIN' 附近的语法不正确。”
SQL Multiple Joins returning error 'Incorrect syntax near the keyword 'JOIN'.'
我是 SQL 的新手,正在尝试与 SQL 服务器进行一些多重连接。
给定
c_slpn
:
"ID Name Age Salary"
'1 Abe 61 140000'
'2 Bob 34 44000'
'5 Chris 34 40000'
'7 Dan 41 52000'
'8 Ken 57 115000'
'11 Joe 38 38000'
c_cust
:
"ID Name City Industry Type"
'4 Comp1 pleasant J'
'6 Comp2 oaktown J'
'7 Comp3 jackson B'
'9 Comp4 Jackson B'
c_ordr
:
"Number order_date cust_id salesperson_id Amount"
'10 8/2/96 4 2 540'
'20 1/30/99 4 8 1800'
'30 7/14/95 9 1 460'
'40 1/29/98 7 2 2400'
'50 2/3/98 6 7 600'
'60 3/2/98 6 7 720'
'70 5/6/98 9 7 150'
我应该找到“列出有 'Comp1' 订单的销售人员,但下面的脚本抛出错误:
Line 6 'Incorrect syntax near the keyword 'JOIN'.
查询:
SELECT *
FROM c_cust
JOIN C_ordr ON C_ordr.cust_id= c_cust.ID
WHERE NAME = 'Comp1'
JOIN c_slpn ON c_slpn.id=c_ordr.cust_id
请帮助我...,我卡住了:-p [这是我的第一个问题,我是不是漏掉了什么]
WHERE
子句在 JOIN
:
之后
SELECT *
FROM c_cust
JOIN C_ordr ON C_ordr.cust_id = c_cust.ID
JOIN c_slpn ON c_slpn.id = c_ordr.salesperson_id
WHERE c_cust.NAME = 'Comp1'
顺便说一下,你也可以在 JOIN
子句中这样做,比如 C_ordr.cust_id = c_cust.ID AND c_cust.NAME = 'Comp1'
。
不确定这是否只是打字错误,但您的 table 名称不一致。
SELECT *
FROM c_cust
JOIN c_ordr
ON c_ordr.cust_id= c_cust.ID
JOIN c_slpn
ON c_slpn.id=c_ordr.cust_id
WHERE c_cust.Name= 'Comp1'
我是 SQL 的新手,正在尝试与 SQL 服务器进行一些多重连接。
给定
c_slpn
:
"ID Name Age Salary"
'1 Abe 61 140000'
'2 Bob 34 44000'
'5 Chris 34 40000'
'7 Dan 41 52000'
'8 Ken 57 115000'
'11 Joe 38 38000'
c_cust
:
"ID Name City Industry Type"
'4 Comp1 pleasant J'
'6 Comp2 oaktown J'
'7 Comp3 jackson B'
'9 Comp4 Jackson B'
c_ordr
:
"Number order_date cust_id salesperson_id Amount"
'10 8/2/96 4 2 540'
'20 1/30/99 4 8 1800'
'30 7/14/95 9 1 460'
'40 1/29/98 7 2 2400'
'50 2/3/98 6 7 600'
'60 3/2/98 6 7 720'
'70 5/6/98 9 7 150'
我应该找到“列出有 'Comp1' 订单的销售人员,但下面的脚本抛出错误:
Line 6 'Incorrect syntax near the keyword 'JOIN'.
查询:
SELECT *
FROM c_cust
JOIN C_ordr ON C_ordr.cust_id= c_cust.ID
WHERE NAME = 'Comp1'
JOIN c_slpn ON c_slpn.id=c_ordr.cust_id
请帮助我...,我卡住了:-p [这是我的第一个问题,我是不是漏掉了什么]
WHERE
子句在 JOIN
:
SELECT *
FROM c_cust
JOIN C_ordr ON C_ordr.cust_id = c_cust.ID
JOIN c_slpn ON c_slpn.id = c_ordr.salesperson_id
WHERE c_cust.NAME = 'Comp1'
顺便说一下,你也可以在 JOIN
子句中这样做,比如 C_ordr.cust_id = c_cust.ID AND c_cust.NAME = 'Comp1'
。
不确定这是否只是打字错误,但您的 table 名称不一致。
SELECT *
FROM c_cust
JOIN c_ordr
ON c_ordr.cust_id= c_cust.ID
JOIN c_slpn
ON c_slpn.id=c_ordr.cust_id
WHERE c_cust.Name= 'Comp1'