我的IN子句适用于第一个查询,但不适用于第二个查询。没有IN子句,较大的查询工作正常,因此没有问题。通过文档查看,但无法看到我出错的地方。
使用:
'SELECT email, first_name, last_name
FROM users
WHERE user_id
IN (' . implode(',', array_map('intval',$userData)) . ')'
不起作用:
'SELECT
u.user_id, u.email, u.first_name, u.last_name, a.job_id, a.user_id, ap.job_id, ap.app_id, ap.location, p.user_id, p.filename, p.selected, g.street, g.city, g.state
FROM users u
JOIN applications ap ON ap.user_id = u.user_id
JOIN applicants a ON a.user_id = a.user_id AND a.app_id = ap.app_id AND ap.job_id = a.job_id
LEFT OUTER JOIN user_photos p ON u.user_id = p.user_id AND p.selected = 1
LEFT OUTER JOIN user_general g ON u.user_id = g.user_id
WHERE
u.user_id IN (' . implode(',', array_map('intval',$userData)) . ')'
错误:
无法执行查询。您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在附近使用')'第9行
答案 0 :(得分:0)
您的derived_class
函数最终会返回一个空字符串,因此您会看到此问题。
以implode
关键字显示空值为例,注意类似错误。
in
答案 1 :(得分:0)
'SELECT
u.user_id, u.email, u.first_name, u.last_name,
a.job_id, a.user_id, ap.job_id, ap.app_id, ap.location,
p.user_id, p.filename, p.selected, g.street, g.city, g.state
FROM users u
LEFT OUTER JOIN applications ap ON ap.user_id = u.user_id
JOIN applicants a ON a.user_id = a.user_id AND a.app_id = ap.app_id AND ap.job_id = a.job_id
LEFT OUTER JOIN user_photos p ON u.user_id = p.user_id AND p.selected = 1
LEFT OUTER JOIN user_general g ON u.user_id = g.user_id
WHERE
u.user_id IN (' . implode(',', array_map('intval',$userData)) . ')'