sql >> Base de Datos >  >> RDS >> Mysql

Consulta MySQL:problema con el pedido por

¿Qué tal algo como

SELECT DISTINCT messages.fromid, 
            messages.readed, 
            messages.fromid, 
            messages.toid  , 
            members.id AS pid 
FROM            messages 
INNER JOIN members 
ON              members.id = messages.fromid 
WHERE           messages.toid              =  ".$mid." 
AND             members.status             = 7 
AND             messages.kreaded          !='1' 
AND             messages.subject          != 'readed'
ORDER BY    messages.fromid ASC,
            messages.id DESC

O

SELECT DISTINCT messages.fromid, 
            messages.readed, 
            messages.fromid, 
            messages.toid  , 
            members.id AS pid 
FROM            messages 
INNER JOIN members 
ON              members.id = messages.fromid 
WHERE           messages.toid              =  ".$mid." 
AND             members.status             = 7 
AND             messages.kreaded          !='1' 
AND             messages.subject          != 'readed'
ORDER BY    messages.fromid ASC,
            messages.sendtime DESC

En mensajes.fromid ASC el ASC es puramente sintácticamente, ya que ORDER BY sin especificar ASC/DESC asume ASC.

SELECT *
FROM TABLE
ORDER BY COL ASC

es lo mismo que

SELECT *
FROM TABLE
ORDER BY COL