Have a look at
this. Querying in vBulletin is different from querying in PHP - vBulletin wraps all queries within a database object so that it's possible in the future to allow multiple database types (though there are still reasons why they haven't implemented it now, mainly MySQL-only functions they've used I think).
The basic query for SELECT statements is:
PHP Code:
$db->query_read ( SQL );
// And the way to lay out queries conforming to the way vBulletin does it is:
$db->query_read("
SELECT *
FROM " . TABLE_PREFIX . "random_table
WHERE id=$whatever_id
ORDER BY id ASC, age DESC
LIMIT 0, 10
");
// Each new command is on a new line and indented.
As I say though, have a look at the tutorials in there.