php - 从三个表中获取数据但出现 SQL 语法错误
问题描述
我正在从三个表中获取数据:
$result = $this->db->query("
SELECT
`meetings`.*,
`follow_up`.id as follow_up_id,
`follow_up`.comment as follow_up_comment,
`follow_up`.date as follow_up_date,
`follow_up`.time as follow_up_time,
SELECT first_name, last_name, user_mobile, useralt_mobile from users where id = user_id,
(SELECT address FROM day_location WHERE `meetings`.assigned_to_id = user_id AND `follow_up`.date = date LIMIT 1) AS location_name
FROM meetings
LEFT JOIN follow_up ON `meetings`.id = `follow_up`.`meeting_id`
WHERE follow_up.`date` BETWEEN '{$fromDate_formated}' AND '{$toDate_formated}'
" . ($user_id > 0 ? " AND `meetings`.assigned_to_id = '{$user_id}'" : '') . "
ORDER BY `follow_up`.id DESC
");
错误:
A Database Error Occurred
错误编号:1064
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在第 7 行的 'SELECT first_name, last_name, user_mobile, useralt_mobile from users where id = ' 附近使用
SELECTmeetings
.*,follow_up
.id as follow_up_id,follow_up
.comment as follow_up_comment,follow_up
。日期为 follow_up_date,follow_up
.time 为 follow_up_time,从 id = user_id 的用户中选择 first_name、last_name、user_mobile、useralt_mobile,(从 day_location 选择地址 WHEREmeetings
.assigned_to_id = user_id ANDfollow_up
.date = 日期限制 1)作为会议的 location_name 左加入 follow_upmeetings
.id =follow_up
.meeting_id
在哪里跟进。date
在 '2018-10-01' AND '2018-10-31' ANDmeetings
.assigned_to_id = '1' ORDER BYfollow_up
.id DESC之间
你能帮忙吗?
解决方案
你需要替换这个:
SELECT first_name, last_name, user_mobile, useralt_mobile from users where id = user_id,
有了这个:
(SELECT first_name, last_name, user_mobile, useralt_mobile from users where id = user_id),
推荐阅读
- python - 如何将python脚本的输出保存为json而不是对象流?
- python - 创建一个 3x3 矩阵的 n 维 NumPy 数组
- primefaces - Primefaces升级期间jQuery未定义
- java - JDK 中的 StringBuilder 与 "+" >= 9
- r - R - 回归系数的显着性检验
- react-native - 无法在 React-navigation 的 useFocusEffect 内实现回调
- php - 为什么用ajax再次填充数据时dataTable的分页不起作用?
- python - 如何从 numpy 数组创建 NxM 矩阵?
- node.js - 无法使用 EJS 模板在 express 节点 js 中显示对象数组中的值
- csv - 如何从 perl 脚本创建和下载 csv 文件