I have two tables: #__records and #__parents. In the first table some records may have parent records that are stored in the same table but relations between childs and parents are stored in the second table. For example
#__records:
id name
1 Child1
2 Child2
3 Parent1
#__parents
id child parent
1 2 3
2 1 3
Now I have the query:
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('a.id, a.name')
->from('#__records as a');
$query->select('b.parent as parentid');
$query->join('LEFT', '#__parents AS b ON b.child = a.id');
$db->setQuery($query);
return $query;
It returns the names of records (a.name) but with IDs of parents (b.parent). I need the second "left join" or another way to get the names of parents instead of their IDs. Something like:
select c.name as parentname from #__records as c where c.id=b.parent