How to use "db_query" instead of "db_select"?
db_query can be used with an actual MySQL query - you just insert the MySQL query as you would in, say, PHPMyAdmin or some other UI for MySQL (or command line).

You can also substitute arguments into the query based on the second argument passed to the function, as such (found on Drupal.org as an example):

$result = db_query('SELECT n.nid, n.title, n.created FROM {node} n WHERE n.uid = :uid', array(':uid' =&gt; $uid));


Here the $uid variable is being passed as an argument to the query. Theoretically you could also write this as such:

$result = db_query('SELECT n.nid, n.title, n.created FROM {node} n WHERE n.uid = ' . $uid);


As Clive mentions in the comments though, this is just for illustrative purposes, as it does open you up to potential attack.