Select deleting another Select

0

Well my scenario is as follows, I have 1 slide where shows the last 4 news

SELECT * FROM noticias WHERE destacar='Destacado' ORDER BY idnoticia DESC LIMIT 4

Under the slide I have a list of the other subjects where you should present the ones not marked NOT HIGHLIGHT and those marked HIGHLIGHT from the 4th result, I am using the following query.

SELECT * FROM noticias n WHERE idnoticia NOT IN ( SELECT * FROM (SELECT idnoticia FROM noticias WHERE destacar = 'Destacado' ORDER BY idnoticia ASC LIMIT 10) p) ORDER BY idnoticia DESC LIMIT 9 OFFSET 4

This is working in parts, it is listed from the 4th result but if I include a notice in the middle (assuming it is between the 2nd and 4th HIGHLIGHT) marked NOT HIGHLIGHT it does not appear.

Some way around this problem?

    
asked by anonymous 02.04.2015 / 02:52

1 answer

1

Without the bank at hand it is difficult to test, but test in this way, you do not need OFFSET because the first 4 will be ignored in NOT IN :

SELECT 
  * 
FROM
  noticias 
WHERE idnoticia NOT IN 
  (SELECT 
    idnoticia 
  FROM
    noticias 
  WHERE destacar = 'Destacado' 
  ORDER BY idnoticia DESC 
  LIMIT 4) 
ORDER BY idnoticia DESC 
LIMIT 9 

Hope it helps

Hugs

    
02.04.2015 / 05:58