Access query error (“syntax error in from clause”)

爱⌒轻易说出口 提交于 2019-12-02 08:28:31

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.

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

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

You have reversed the inner join and where clauses. You should write the SQL like this:

SELECT * 
  FROM Dept 
 INNER JOIN Userinfo ON Dept.Deptid = Userinfo.Deptid
 INNER JOIN Checkinout ON Userinfo.Name = Checkinout.name"
 WHERE Dept.DeptName = '$departamento'

Probably should be:

SELECT * FROM Dept 
INNER JOIN Userinfo ON Dept.Deptid = Userinfo.Deptid 
INNER JOIN Checkinout on Userinfo.Name = Checkinout.name 
where Dept.DeptName = '$departamento' 

I think it should be :

SELECT * FROM (Dept 
INNER JOIN Userinfo ON (Dept.Deptid = Userinfo.Deptid)) 
INNER JOIN Checkinout ON (Userinfo.Name = Checkinout.name)
WHERE Dept.DeptName = '$departamento'

what i decided to do is to use 2 different queries:

$consulta=  "SELECT * FROM Dept INNER JOIN Userinfo 
         ON Userinfo.Deptid = Dept.Deptid
         where Dept.DeptName = '$departamento'";

and

$consulta2 = "SELECT  *  FROM Checkinout, Userinfo
    where Checkinout.Userid = '$userid' AND  Userinfo.userid = '$userid' AND 
    Checkinout.Checktime BETWEEN CDate('$fecha1') AND CDate('$fecha2')"; 

The first one to select all the people that belong to one deparment, and the second one to find all the INs and OUTs of one person. Both in a while to be able to look each register of the first result and check with the other query


still have problems with the search, its not working fine, im trying to do a full query where it searchs in the 3 tables at the same time but its giving me a error:

$toda_consulta= "SELECT * 
                     FROM Dept 
                     INNER JOIN Userinfo ON (Dept.Deptid = Userinfo.Deptid)
                     INNER JOIN Checkinout ON (Checkinout.Userid = Userinfo.Userid)
                     WHERE Dept.DeptName = '$departamento' AND 
                           Checkinout.Checktime BETWEEN CDate('$fecha_inicio') AND CDate('$fecha_fin')";

error: Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][Controlador ODBC Microsoft Access] sintax error (missing operator) in the expression '(Dept.Deptid = Userinfo.Deptid) INNER JOIN Checkinout ON (Checkinout.Userid = Userinfo.Userid)'., SQL state 37000 in SQLExecDirect in C:\wamp\www\casa 7-9-13\calcula_departamento1.php on line 51

than you for your help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!