Double rule in LIMIT

7

I have a news table with the fields titulo , conteudo and destaque , the highlight being int (1), is a Boolean value only to check if a news item is highlighted or not, what would you like to do is to select a quantity of news and within that amount X news need to be highlights ( destaque=1 ), something like this:

SELECT * FROM noticias WHERE destaque = 1 limit 5 AND ... LIMIT 30.

That is, 30 news items, 5 of them are highlights and the rest (25) are "common."

How can I do this?

    
asked by anonymous 23.12.2018 / 00:06

1 answer

6

Take the 5 that need one criterion, that is, they are highlighted, and then take 25 others that do not need this criterion.

SELECT * FROM noticias WHERE destaque = 1 limit 5
UNION ALL
SELECT * FROM noticias WHERE destaque <> 1 limit 25

I doubt this is a query that produces an interesting result, but it does meet the criteria put in the question.

    
23.12.2018 / 00:26