I’m trying to query two joined database tables via the API and return columns from both tables. All attempts have so far only returned columns from one table.
Any ideas on returning columns from both tables?
Could you post your code pls?
Of course. It was basically like this:
$db = new Database(array(stuff here));
$items = $db->table(‘table1’)->innerJoin(‘table2’,‘table1.field1 = table2.field2’)->where(‘table1.field1’,’=’,‘something’)->all();
print_r($items); /* no columns from table2 in here
Any help or pointers very welcome. Thanks!
Hm, I’m not really familiar with the database class, but there seems to be a select statement missing:
$items = $db->table('table1')->select('column')-> ...
The following code worked for me …
$n = $db->table('node');
$results_n = $n->select('*')
->join('content_type_event','node.nid = content_type_event.nid')
->where(array('type' => 'event', 'status' => '1'))
To debug your query you can do the following after running your query:
Both will probably help you to understand better why your query fails.