Tema: limit
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 22/09/2015, 14:12
Avatar de gnzsoloyo
gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: limit

No tiene errores sintácticos, si eso es lo que pregutnas.
Si, debes tener en cuenta dos cosas: 1) Las fechas deben estar en un campo DATE, DATETIME o TIMESTAMP. Ningun otro funciona con fechas; y 2) EL ORDER BY con uso de LIMIT puede causar algunos resultados raros.
Cita:
If you combine LIMIT row_count with ORDER BY, MySQL ends the sorting as soon as it has found the first row_count rows of the sorted result, rather than sorting the entire result. If ordering is done by using an index, this is very fast. If a filesort must be done, all rows that match the query without the LIMIT clause are selected, and most or all of them are sorted, before the first row_count are found. After the initial rows have been found, MySQL does not sort any remainder of the result set.

One manifestation of this behavior is that an ORDER BY query with and without LIMIT may return rows in different order, as described later in this section.
En esencia, el LIMIT actúa con mayor prioridad que el ORDER BY, es decir, puede no haber ordenado el total de resultados posibles, antes de devolver los registros pedidos.
En ese caso lo mejor es usar el SELECT con ORDER BY como tabla derivada:
Código MySQL:
Ver original
  1. FROM (SELECT * FROM productos
  2.     WHERE alta='1'
  3.     ORDER BY fecha DESC) Tabla
  4. LIMIT 0,20
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)