Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL-Abfrage - Problem mit Sortieren nach

Wie wäre es mit so etwas wie

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

ODER

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 der ASC ist rein syntaktisch, da ORDER BY ohne Angabe von ASC/DESC ASC voraussetzt.

SELECT *
FROM TABLE
ORDER BY COL ASC

ist dasselbe wie

SELECT *
FROM TABLE
ORDER BY COL