我想获取第一个表中的id和第二个表中的信息,但前提是第二个表中有任何相关行,并且相关行的最大日期比现在时间小(早先) ...
这就是我现在所拥有的:
"SELECT t1.id as actID, t2.id AS eventsid, t2.controlled FROM `activites` t1
LEFT JOIN `events` t2 ON t2.activitesid = t1.id
WHERE t2.datum < UNIX_TIMESTAMP() GROUP BY t2.controlled"
我一直在尝试的是
"SELECT t1.id as actID, t2.id AS eventsid, t2.controlled FROM `activites` t1
LEFT JOIN `events` t2 ON t2.activitesid = t1.id
WHERE (SELECT `datum` FROM `events` t3 WHERE t3.controlled = t2.controlled ORDER BY `datum` DESC LIMIT 1) < UNIX_TIMESTAMP() GROUP BY t2.controlled"
有没有人能指出我的方向或如何输入这种查询?
没有必要指出我应该使用PDO,mysqli等......