Skip to content

Instantly share code, notes, and snippets.

@elhoyos
Created May 29, 2012 20:41
Show Gist options
  • Save elhoyos/2830593 to your computer and use it in GitHub Desktop.
Save elhoyos/2830593 to your computer and use it in GitHub Desktop.
Sort by two factors
-- Todos los artículos de 'RAFA' primero ordenados por serial y luego el resto de artículos ordenados igualmente por serial.
SELECT a.* FROM articulos a LEFT JOIN (SELECT 'RAFA' COLLATE utf8mb4_general_ci AS nombre) r on r.nombre = a.usuario
ORDER BY r.nombre DESC, serial
--
-- Base de datos: `pruebas`
--
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `articulos`
--
CREATE TABLE `articulos` (
`id` int(11) NOT NULL,
`serial` varchar(50) DEFAULT NULL,
`usuario` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Volcado de datos para la tabla `articulos`
--
INSERT INTO `articulos` (`id`, `serial`, `usuario`) VALUES
(1, 'A', 'RAFA'),
(2, 'B', 'JUAN'),
(3, 'F', 'JAIME'),
(4, 'C', 'JAIME'),
(5, 'D', 'JUAN'),
(6, 'E', 'RAFA');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment