通过C#(VS 20015)的SQL Server 2005。知道为什么WHERE
不起作用?
SQL语句是:
SELECT
AA003Employee.idEmployee,
AA001Person.LastName, AA001Person.FirstName,
AA017JobTitle.JobTitle, AA017JobTitle.Department,
AA003Employee.Disabled
FROM
AA003Employee
JOIN
AA001Person ON AA003Employee.idPerson = AA001Person.idPerson
JOIN
AA017JobTitle ON AA003Employee.idJobTitle = AA017JobTitle.idJobTitle
ORDER BY
AA001Person.LastName ASC, AA001Person.FirstName ASC,
AA017JobTitle.JobTitle ASC
WHERE
AA003Employee.Disabled = 'N';
尝试过:
省略->
WHERE AA003Employee.Disabled = 'N'
时效果很好当我尝试将其替换为->“ ...
WHERE Disabled = 'N'";
时,它将引发错误这是错误的屏幕截图:
最佳答案
您的问题是WHERE
子句的位置。 SQL关心语句中子句的顺序。但是,您还应该学习使用表别名:
SELECT e.idEmployee, p.LastName, p.FirstName, jt.JobTitle, jt.Department, e.Disabled
FROM AA003Employee e JOIN
AA001Person p
ON e.idPerson = p.idPerson JOIN
AA017JobTitle jt
ON e.idJobTitle = jt.idJobTitle
WHERE e.Disabled = 'N'
ORDER BY p.LastName ASC, p.FirstName ASC, jt.JobTitle ASC;
看到?该查询更容易编写和阅读。