我想解决我的Sql查询

时间:2013-02-05 06:57:01

标签: mysql sql join

SELECT 
    a.studentcode, 
    a.studentname, 
    a.fathername, 
    a.date, 
    c.centrename, 
    cm.feename, 
    l.location, 
    a.periodofissue, 
    a.image 
FROM admission a 
INNER JOIN centre c ON a.centreid = c.id 
INNER JOIN coursemaster cm ON a.courseid = cm.id 
INNER JOIN location l ON a.locationid = l.id where a.id in (".$pc.")

并在执行查询后发生错误:

  

“您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在”)“附近使用正确的语法       1 SELECT a.studentcode, a.studentname, a.fathername, a.date, c.centrename, cm.feename, l.location, a.periodofissue, a.image FROM admission a INNER JOIN centre c ON a.centreid = c.id INNER JOIN coursemaster cm ON a.courseid = cm.id INNER JOIN location l ON a.locationid = l.id where a.id in ()

请给我解决方案

1 个答案:

答案 0 :(得分:0)

也许尝试类似的事情:

SELECT a.`studentcode` , a.`studentname` , a.fathername, a.date, 
       c.`centrename` , cm.`feename` , l.`location`, 
       a.periodofissue, a.image 
FROM admission a 
INNER JOIN centre c ON a.centreid = c.id 
INNER JOIN coursemaster cm ON a.courseid = cm.id 
INNER JOIN location l ON a.locationid = l.id 
where a.id in (select id from admission where id = ".$pc.")

或者:

SELECT a.`studentcode` , a.`studentname` , a.fathername, a.date, 
       c.`centrename` , cm.`feename` , l.`location`, 
       a.periodofissue, a.image 
FROM admission a 
INNER JOIN centre c ON a.centreid = c.id 
INNER JOIN coursemaster cm ON a.courseid = cm.id 
INNER JOIN location l ON a.locationid = l.id 
where a.id = ".$pc."