Referencing Embedded SQL statement
I have the following SQL:
SELECT `job`.`id`,`subject`,`status`,
`userID`,`vocation`,`flag`, UNIX_TIMESTAMP(`ts`) as `ts`,`exchangeID`,
(SELECT `polyflag` FROM `exchange` WHERE
`exchange`.`foreignID`=`job`.`id`
AND DATE_FORMAT(FROM_UNIXTIME(`exchange`.`ts`),'%m-%d') =
DATE_FORMAT(NOW(),'%m-%d')
ORDER BY `ts` DESC LIMIT 1) as `polyflag`
FROM `team`
LEFT JOIN `job` ON `team`.`foreignID` = `job`.`id`
WHERE `userID` = '2'
AND `team`.`table`='job'
AND `job`.`status` = 'COMPLETE'
OR `job`.`status` = 'DEFERRED'
ORDER BY `job`.`ts`,`status` DESC, `vocation` DESC;
The problem is, (and I am new to embedded SQL statements, so forgive me)
is that I want to move the DATE_FORMAT line from the embedded WHERE to the
'outer' WHERE (hope that makes sense). I only want to view rows that
contain a polyflag from Today.
No comments:
Post a Comment