Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This seems to be an issue stemming from the <code>SELECT *</code> and <code>GROUP BY</code>. <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-extensions.html" rel="nofollow">MySQL</a> allows this to happen, but it can cause some issues.</p> <blockquote> <p>MySQL extends the use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause. This means that the preceding query is legal in MySQL. You can use this feature to get better performance by avoiding unnecessary column sorting and grouping. However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. <strong>The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate</strong>. Furthermore, <strong>the selection of values from each group cannot be influenced by adding an ORDER BY clause</strong>. Sorting of the result set occurs after values have been chosen, and ORDER BY does not affect which values within each group the server chooses.</p> </blockquote> <p>As far as getting the data you want, I think <a href="http://www.sqlfiddle.com/#!2/741a5/5" rel="nofollow">this</a> will work for you:</p> <pre><code>SELECT * FROM `messages` ORDER BY m_from ASC, m_time DESC </code></pre> <p>If you want it sorted by time first, just move <code>m_from ASC</code> to the end</p> <p><strong>EDIT</strong></p> <p>Given your updated question, this should limit the columns to what you want:</p> <pre><code>SELECT m_from, m_time FROM `messages` ORDER BY m_from ASC, m_time DESC </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload