访问查询错误("from子句中的语法错误") [英] Access query error ("syntax error in from clause")

查看:73
本文介绍了访问查询错误("from子句中的语法错误")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$consulta3 = "SELECT * FROM Dept INNER JOIN Userinfo INNER JOIN Checkinout
                     on Dept.DeptName = '$departamento'
                     where Dept.Deptid = Userinfo.Deptid AND Userinfo.Name = Checkinout.name";

我想用此查询执行的操作是:我有一个名为Dept的表,其中包含所有部门名称和ID,具有用户名,部门ID和ID的用户信息.另外,我还有一个名为checkinout的第三张表,该表具有用户ID和时间.

the thing im trying to do with this query is: i have a table called Dept where it has all the deparments names and ids, User info that has user name, a department id and a id. Also i have a 3rd table called checkinout that has user id, with a time.

因此,我想(使用部门名称)从属于该部门人员的Checkinout表中获取所有数据,但是当我尝试该查询时,它给了我一个错误:

So i want (using the deparment's name) to bring all the data from the Checkinout table from the people that belongs to that deparment, but when i try that query it gives me an error:

syntax error in from clause. sql state 37000 in sqlexecdirect

,我解决不了.我正在使用Acces数据库.

and i cant solve it. Im using a Acces Data base.

非常感谢您的帮助.

推荐答案

访问绝对需要在包含多个连接的任何查询的FROM子句中加括号.如果您具有Access可用,请在查询设计器中创建并测试新查询.设计器有用的原因之一是,它知道使数据库引擎满意的括号规则.

Access absolutely requires parentheses in the FROM clause of any query which includes more that one join. If you have Access available, create and test a new query in the query designer. One of the reasons the designer is useful is that it knows the rules for parentheses which keep the db engine happy.

从与此类似的查询开始.此时,不必担心基于Dept.DeptName进行过滤.只需确保正确设置了联接即可.

Start with a query similar to this. Don't worry about filtering based on Dept.DeptName at this point. Just make sure the joins are set up correctly.

SELECT *
FROM
    (Dept
    INNER JOIN Userinfo
    ON Dept.Deptid = Userinfo.Deptid)
    INNER JOIN Checkinout
    ON Userinfo.Name = Checkinout.name

正确设置联接后,添加过滤器约束(WHERE Dept.DeptName ...).

After you have the joins set up correctly, add in your filter constraint (WHERE Dept.DeptName ...).

这篇关于访问查询错误("from子句中的语法错误")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆