I have a small problem, want to find records with a datefield in the last 24 hours, which also works great:
SELECT * FROM `release` WHERE (date >= now() - INTERVAL 1 DAY)
Now I want to sort the records after a column from another table, also works:
SELECT * FROM `release` AS r JOIN hits as h ON h.id = r.id ORDER BY h.hits DESC LIMIT 0,8
Now to my problem, I get it not to both to cobble, here my attempt (am still very new with Mysql):
SELECT * FROM `release` WHERE (date >= now() - INTERVAL 1 DAY) AS r JOIN hits as h ON h.id = r.id ORDER BY h.hits DESC LIMIT 0,8
But that does not work, why would be nice if someone could explain it to me.
Thank you in advance already times.
答案 0 :(得分:0)
您的查询已加入错误的位置..根据您的需要,您可以使用带有选择结果的From
SELECT *
FROM
( select * from `release`
WHERE (date >= now() - INTERVAL 1 DAY
DESC LIMIT 0,8 ) r
JOIN hits as h ON h.id = r.id
ORDER BY h.hits
答案 1 :(得分:0)
您可以在此之后简单地加入并添加where子句。
SELECT * FROM
{释放{1}}