How could I do a FULL OUTER JOIN in drupal? How can I do this code in Drupal? I cannot find how this code is writing in Drupal.

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name;
Dynamically it would look like this:

$q = db_select('table1')
  -&gt;fields('table1', array('column_name'));

$q-&gt;addJoin('FULL OUTER', 'table2', NULL, 'table1.column_name = table2.column_name');


Which will give you

SELECT table1.column_name AS column_name
FROM 
{table1} table1
FULL OUTER JOIN {table2} table2 ON table1.column_name = table2.column_name


Or you can run any SQL string with db_query():

$sql = &lt;&lt;&lt;SQL
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name;
SQL;

$result = db_query($sql);