Mysql
 sql >> Database >  >> RDS >> Mysql

Query MySQL - problema con l'ordine di

Che ne dici di qualcosa del genere

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

In messages.fromid ASC l'ASC è puramente sintatticamente, poiché ORDER BY senza specificare ASC/DESC presuppone ASC.

SELECT *
FROM TABLE
ORDER BY COL ASC

è uguale a

SELECT *
FROM TABLE
ORDER BY COL