Question: I'm trying to learn how to make select queries with Drupal, so I made a form, and when I submit the form I try to query the database and get some results, but instead I'm redirected to an error page, here's how I select nodes from DB :

```
function my_module_form_submit($form, &$form_state)
{
    $query = db_select('node', 'n')->extend('PagerDefault');
    $query->condition('type', 'myContentType');
    $result = $query->execute();
}

```

Answer: 
You have missed fields() & fetch type -- fetchAll().

Below is the working example. You can find more details here [(db\_select API)](https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_select/7) 

```
$query = db_select('node', 'n')->extend('PagerDefault');
$query->fields('n'); // This is like select *. You can retrieve specific fields too.
$query->condition('type', 'article');
$result = $query->execute()->fetchAll(); // you can fetch by object, array, etc...
print_r($result);

```
I don't know exactly what was the issue with the code I used before, but using a more advanced query resolved the problem ( being redirected to an error page ) :

```
$query = db_select("node", "n");
$query->fields("n", array("nid"));
$query->fields("n", array("created"));
$query->fields("n", array("type"));

$query->fields("f1", array('field_f1_value'));
$query->fields("f2", array('field_f2_value'));
//...

$query->leftJoin('field_data_f1', 'f1', 'f1.entity_id = n.nid');
$query->leftJoin('field_data_f2', 'f2', 'f2.entity_id = n.nid');
// ...

$query->condition('n.type', 'voitures_d_occasion', '=');
$query = $query->orderBy('n.created', 'DESC');
$query = $query->extend('TableSort')->extend('PagerDefault')->limit(10);
$result = $query->execute();

```