I am fetching data from three tables:
$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
");
Error:
A Database Error Occurred
Error Number: 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 'SELECT first_name, last_name, user_mobile, useralt_mobile from users where id = ' at line 7
SELECTmeetings
.*,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 WHEREmeetings
.assigned_to_id = user_id ANDfollow_up
.date = date LIMIT 1) AS location_name FROM meetings LEFT JOIN follow_up ONmeetings
.id =follow_up
.meeting_id
WHERE follow_up.date
BETWEEN '2018-10-01' AND '2018-10-31' ANDmeetings
.assigned_to_id = '1' ORDER BYfollow_up
.id DESC
Can you please help?
SELECT first_name, last_name,...
is supposed to do? – Felippe DuarteJOIN
's instead of these sub-queries. – jeroen