I have a news database table that has two kinds of articles in it: social and official (mutually exclusive).
What I would like to do is reduce the number of social rows in the table to a specific number, while leaving the official news articles alone.
Here is what I’ve come up with so far:
DELETE
FROM News
WHERE _id NOT IN
(SELECT _id
FROM News
WHERE IsOfficialNews=0
ORDER BY Date DESC LIMIT 20
UNION SELECT _id
FROM News
WHERE IsOfficialNews=1)
However, I get an error that states ORDER BY clause should come after UNION not before. Moving the ORDER BY to the end of the inner SELECT results in LIMIT clause should come after UNION not before.
I understand the error message but I wonder if there is some other way to accomplish what I’m trying to do. If I move the LIMIT clause to the end of the inner SELECT then I will still have more than 20 social rows left in the table (because it will also count official rows).
Maybe like this (see comment above):