Q:

Custom query in drupal views - now can't sort

The view with the custom query is being displayed in the right sidebar titled "Most Downloaded" here: http://tf2huds.com. The view with the query generated by views is right below it.
To put in the custom query I'm using this code in the views.module file:
<?php
function views_views_pre_execute(&$view) {
   if($view->name=="hud_downloads") {
     $view->build_info['query']="SELECT node.nid AS nid, 
         node.title AS node_title, 
         SUM(pubdlcnt.count) AS pubdlcnt_count 
         FROM node node 
         LEFT JOIN pubdlcnt pubdlcnt ON node.nid = pubdlcnt.nid  
         WHERE (node.type in ('huds')) AND (node.status <> 0) 
         GROUP BY node.nid ORDER BY pubdlcnt_count DESC";
     }
}
?>

Pastebins:

block with custom query: http://pastebin.com/QTrp1kpt
block without custom query: http://pastebin.com/9GRviPer (relevant block is Block_3)

Any idea why I can't sort my view? Thanks in advance.

A:

You cannot sort the view, because you are hard-coding the SQL to always be the same. So when you change the SQL with views, via the table, it get's overwritten by your views_views_pre_execute function.

