Greetings,

I have 3 tables in Joomla 2.5 from which I need to get data and display it.
Now the query works till its 2 tables but as soon as I join a 3rd table it does not work.

This works perfectly fine :

Code:
function getData($idData,$idValue) {
	$db = JFactory::getDbo();
	$sql = $db->getQuery(true);
	$sql
	->select(array('st.id', 'st.name', 'st.date', 'st.currentstat', 'li.title', 'li.id'))
	->from('#__joomla_data AS st')  
	->where('st.name ='.$idData)       
	->join('INNER', '#__joomla_cont AS li ON (st.currentstat = li.id) AND (li.title="'.$idValue.'")' )
	->order('st.date ASC');
	$db->setQuery($sql);
    $query_result = $db->loadObjectList();
    $date_print = '';
    foreach($query_result as $query_results){
  	$pdate = date("M,D-Y", strtotime($query_results->date));
	$date_print .= $pdate .'<br/>';
  }
    return $date_print;
}
Now I have another table joomla_maincont which has fields id and name. I want to modify the above query a bit and what I finally need is that ID from joomla_maincont is passed for $idData above.

The query I have to retrieve data for joomla_maincont is this
Code:
select id, name from #__joomla_maincont where name like '$idData-%'
This will always return only one value as all the names are like ID-Name so using like I can get a single row. Now this tables ID, once retrieved needs to be passed to the above query as $idData as that is the ID for joomla_data ID.

Any help how I can achieve the above? Thank you for your help