与别名相关的SQL查询问题

时间:2015-03-05 15:08:09

标签: mysql sql

请有人帮我解决这个问题;

所以我得到了这个SQL查询;

SELECT Route.Number FROM ROUTE INNER JOIN Operator ON Operator.Name =
Route.Operatedby INNER JOIN Operator ON Operator.Name = Route.OperatorName 
WHERE Operator.Description = "Fawcal";

这是我得到的错误;

Not Unique table/alias

1 个答案:

答案 0 :(得分:2)

您要加入同一张桌子两次,请使用Alias

SELECT r.Number 
FROM 
    ROUTE  r INNER JOIN Operator o 
        ON o.Name = r.Operatedby  
    INNER JOIN Operator o2 
        ON o2.Name = r.OperatorName 
WHERE o.Description = "Fawcal";