Ver Mensaje Individual
  #20 (permalink)  
Antiguo 05/04/2007, 17:57
ferret
 
Fecha de Ingreso: abril-2007
Mensajes: 1
Antigüedad: 17 años
Puntos: 0
Re: Ordenar por importancia las 10 ultimas noticias...

SELECT
*
FROM
(
SELECT
*
FROM noticias
ORDER BY id_noticia DESC
LIMIT 0 , 10
)
AS noti
ORDER BY noti.importancia DESC

Usando la tabla de ejemplo:

CREATE TABLE `noticias` (
`id_noticia` int(11) NOT NULL auto_increment,
`importancia` int(11) NOT NULL,
`titulo` varchar(255) NOT NULL,
`texto` varchar(255) NOT NULL,
PRIMARY KEY (`id_noticia`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;

INSERT INTO `noticias` VALUES (1, 5, 'noticia importancia 5', 'test');
INSERT INTO `noticias` VALUES (2, 10, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (3, 8, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (4, 9, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (5, 1, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (6, 2, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (7, 5, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (8, 8, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (9, 2, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (10, 3, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (11, 7, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (12, 6, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (13, 6, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (14, 10, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (15, 9, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (16, 2, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (17, 4, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (18, 4, 'noticia importancia 10', 'test');
INSERT INTO `noticias` VALUES (19, 5, 'noticia importancia 10', 'test');


Los datos son cualquier cosa, porque me daba fiaca cambiar los textos, pero funciona. Version de mysql 5.0.19