title: SQL Select Data That Matches Condition, Display First, Then Sort Remaining Data
body: <p>Just need some help with a SQL statement, I have a table that has a bunch of user data, currently I am getting all the data by rowid descending. However I need to modify the way the data is displayed as follows:</p>
  
  <p>The table has a field in which users can specify their own value or the can choose the default value. When choosing the default value the field is auto populated with a "randomstring_standardefaultvalue". </p>
  
  <p>So basically I need to select all the data in which the user did not choose the defaultvalue and have them order descending and then grab all the rows in which the user selected the defaultvalue and populate them after the first set of data sorted by descending rowid.</p>
  
  <p>My current SQL Looks like this, </p>
  
  <pre><code>$query = "SELECT * FROM userform ORDER BY _rowid_ DESC LIMIT {$offset}, {$pl};";
  </code></pre>
  
  <p>Table Data:</p>
  
  <pre><code>rowid  date  username  defaultoruniquevalue  member  etc...
  </code></pre>
  
  <p>Help would be greatly appreciated.
  Thank You!</p>
  
  <p>ANSWER:</p>
  
  <pre><code>SELECT *, IF(defaultoruniquevalue LIKE CONCAT('%','defaultstring','%'), 1, 0) AS uses_default
  FROM table
  ORDER BY uses_default ASC, _rowid_ DESC
  LIMIT {$offset}, {$pl
  </code></pre>