title: MySQL: Order by Count(*)?
body: <p>I have a table with the following structure (some of you may recognize it as part of a standard vBulletin installation):</p>
  
  <pre><code>mysql&gt; SHOW CREATE TABLE adminlog\G
  *************************** 1. row ***************************
         Table: adminlog
  Create Table: CREATE TABLE `adminlog` (
    `adminlogid` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `userid` int(10) unsigned NOT NULL DEFAULT '0',
    `dateline` int(10) unsigned NOT NULL DEFAULT '0',
    `script` varchar(50) NOT NULL DEFAULT '',
    `action` varchar(20) NOT NULL DEFAULT '',
    `extrainfo` varchar(200) NOT NULL DEFAULT '',
    `ipaddress` varchar(15) NOT NULL DEFAULT '',
    PRIMARY KEY (`adminlogid`),
    KEY `script_action` (`script`,`action`)
  ) ENGINE=MyISAM AUTO_INCREMENT=698189 DEFAULT CHARSET=latin1
  1 row in set (0.02 sec)
  
  mysql&gt;
  </code></pre>
  
  <p>The following query in PHP would select the distinct scripts used by a certain user:</p>
  
  <p><code>"SELECT DISTINCT script FROM adminlog WHERE userid = " . intval($userid)</code></p>
  
  <p>How can I get the query to order the scripts by number of occurrences (for that specific userid), descending? <code>ORDER BY COUNT(*)</code> doesn't do that.</p>