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 :

function getData($idData,$idValue) {
	$db = JFactory::getDbo();
	$sql = $db->getQuery(true);
	->select(array('', '', '', 'st.currentstat', 'li.title', ''))
	->from('#__joomla_data AS st')  
	->where(' ='.$idData)       
	->join('INNER', '#__joomla_cont AS li ON (st.currentstat = AND (li.title="'.$idValue.'")' )
	->order(' ASC');
    $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
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