2014-06-09 2 views
1

Comment sélectionner toutes les lignes d'une table mysql sans N dernières lignes (toute valeur entière).SÉLECTIONNER une requête sans N dernières lignes

J'ai essayé

SELECT * FROM 
      chat 
     WHERE chat_id NOT IN(
        SELECT chat_id FROM chat ORDER BY date_time DESC LIMIT 5 
       ); 

Mais il donne l'erreur suivante

This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' 

Je reçois la version actuelle de MySQL comme suit

mysql> SHOW VARIABLES LIKE 'version'; 
+---------------+------------------+ 
| Variable_name | Value   | 
+---------------+------------------+ 
| version  | 5.1.33-community | 
+---------------+------------------+ 

Répondre

2

Utilisez un LEFT JOIN pour filtrer les lignes correspondant à une Critères.

SELECT c1.* 
FROM chat AS c1 
LEFT JOIN (SELECT chat_id 
      FROM chat 
      ORDER BY date_time DESC 
      LIMIT 5) AS c2 ON c1.chat_id = c2.chat_id 
WHERE c2.chat_id IS NULL 
Questions connexes