check the manual that corresponds to your MySQL server version for the right syntax to use near 'c l


三表联查的sql,检查了格式一些都对,mysql关键词也加了单引号,所有字段也都检查的类型,确定没有问题 ,但是就是报错


原始sql:

SELECT

    c.id,

    u.user_name,

    l.id

FROM

    agent_config AS c

LEFT JOIN agent_level AS l

ON

    c.level = c.id c

LEFT JOIN 'user' ON c.uid = 'user.id'


结果:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'c

LEFT JOIN 'user' ON c.uid = 'user.id' LIMIT 0, 25' at line 9



无奈之下换了另一种写法:

SELECT

    c.id,

    c.domain,

    l.price,

    u.email

FROM

    agent_config c,

    agent_level l,

    USER u

WHERE

    c.level = l.id AND c.uid = u.id

执行正常了,不知道原因,不过还是比较喜欢第一次写法  用习惯了。。


下面顺便巩固下多表查询的


mysql三张表关联查询

鼎云博客

三张表,需要得到的数据是标红色部分的。sql如下:

select a.uid,a.uname,a.upsw,a.urealname,a.utel,a.uremark, b.rid,b.rname,b.rremark,c.deptid,c.deptname,c.deptremark

from table1 a,table2 b,table3 c where a.sems_role_rid=b.rid and a.udeptid=c.deptid 

或者:

select a.uid,a.uname,a.upsw,a.urealname,a.utel,a.uremark, b.rid,b.rname,b.rremark,c.deptid,c.deptname,c.deptremark

from table1 a left join table2 b on  a.sems_role_rid=b.rid left join table3 c on a.udeptid=c.deptid 

LEFT JOIN 可以实现统一数据库多表联合查询符合条件的数据。 


鼎云博客
  • 最新评论
  • 总共0条评论