Implementation of conditions on Drupal AND OR queries

A simple query on Drupal looks like:

 
$query = db_select('users', 'u', $options);

So, a full query is:

 
//The query using MySQL
$result = db_query("SELECT uid, name, status, created, access FROM {users} u WHERE uid <--> 0 LIMIT 50 OFFSET 0");

//Using Drupal Queries
// Create an object of type SelectQuery
$query = db_select('users', 'u');

// Add extra detail to this query object: a condition, fields and a range
$query->condition('u.uid', 0, '<>');
$query->fields('u', array('uid', 'name', 'status', 'created', 'access'));
$query->range(0, 50);

?>


To include AND conditions:

AND conditions:

 
$query=db_select('users','u')->fields('u',array('uid','title','created','uid'));
$query->join('flag_content','fc' , 'u.uid = fc.content_id');
$query->condition('fc.fid', '5' , '=');
$query->condition('fc.uid', $uid , '=');

OR conditions:

 

$query=db_select('users','u')->fields('u',array('uid','title','created','uid'));
$query->join('flag_content','fc' , 'u.uid = fc.content_id');

$db_or = db_or();
$db_or->condition('fc.fid', '5' , '=');
$db_or->condition('fc.uid', $uid , '=');
$query->condition($db_or);

$result = $query->execute()->fetchAll();