How do I use query conditions? I want execute the query SELECT * FROM table WHERE type = 'AAA' AND id = 'BBB'.

The following code works.

$res = db_select('table', 's')
  -&gt;fields('s')
  -&gt;condition('type', $type)
  -&gt;execute()
  -&gt;fetch();

$res = db_select('table', 's')
  -&gt;fields('s')
  -&gt;condition('id', $id)
  -&gt;execute()
  -&gt;fetch();


The following code doesn't work.

$res = db_select('table', 's')
  -&gt;fields('s')
  -&gt;condition('type', $type)
  -&gt;condition('id', $id)
  -&gt;execute()
  -&gt;fetch();


I get an error about the ID not being unique.

UPDATE:

Thanks and sorry. This code works well. I found error in another site.
The code:

$res = db_select('table', 's')
-&gt;fields('s')
-&gt;condition('type', $type)
-&gt;condition('id', $id)
-&gt;execute()
-&gt;fetch();


is not faulty in itself. The problem is probably that you don't have a record with matches both id and type. If you want to make an or query, you need to use db_or