Answer the question
In order to leave comments, you need to log in
How to make a selection from the database by the number of "last 5" and "and all the rest with such and such a value in the field"?
There is a database data:
id, date, sel, tak, mes
I need to select the last five records, plus add all the remaining ones with the parameter tak == 12
SELECT * FORM data ORDER BY date DESC LIMIT 5
How to add "and all the remaining where" to the query tak == 12" so that there are no duplicates if in these of the last five tak can also be equal to 12?
Answer the question
In order to leave comments, you need to log in
if you select everything with one query - union and subquery:
...
where id not in (
SELECT `id`
FORM `data`
ORDER BY date DESC
LIMIT 5
)
and `tak` = 12
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question