Answer the question
In order to leave comments, you need to log in
How to create such query to mysql?
SELECT `id_post`, `time` FROM `posts` GROUP BY `id_post` WHERE `time` BETWEEN FROM_UNIXTIME($min) AND FROM_UNIXTIME($max_time); The problem is GROUP BY `id_post`, and I perfectly understand why, but I don’t have enough experience to form it correctly, how can the resulting value SELECT `id_post`, `time` FROM `posts` GROUP BY `id_post`, be used for WHERE ?
Answer the question
In order to leave comments, you need to log in
GROUP BY is written after WHERE
select tab.*
from ( SELECT `id_post`, `time`
FROM `posts`
GROUP BY `id_post` , `time`
) tab
where tab. `time` BETWEEN FROM_UNIXTIME($min) AND FROM_UNIXTIME($max_time);
1) Given that 'time' is not grouped - in some DBMS such an entry will return an error. What time to display if id_post will be the same 15 and all with different times?
2) WHERE first, then GROUP BY
https://ru.wikipedia.org/wiki/Having_%28SQL%29
if I understand you correctly, you don't need where here.
Can you formulate in plain language what you want to receive as a result of the request?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question