【问题标题】:I want to solve my Sql query我想解决我的 Sql 查询
【发布时间】:2013-02-05 06:57:01
【问题描述】:
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 服务器版本相对应的手册,以获取正确的语法,以便在第 ')' 行附近使用 1SELECT 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.") 似乎为空。根据你得到的错误,它被评估为where a.id in ()
  • $pc 在您的查询中为空。请查看错误。
  • 您尝试在字符串中查找整数
  • @GilPeretz:我知道有时当你只见树木不见树林时会怎样。但是,如果您仔细查看错误消息,它可能只会帮助您找到问题的答案。 :)

标签: mysql sql join


【解决方案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 (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."

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    • 2016-01-25
    • 2021-12-05
    • 1970-01-01
    相关资源
    最近更新 更多