<?php
// Initialize variables.
$db = JFactory::getDbo();
$subQuery = $db->getQuery(true);
$query = $db->getQuery(true);
// Create the base subQuery select statement.
$subQuery->select('subCheckIn')
->from($db->quoteName('#__sub_table'))
->where($db->quoteName('subTest') . ' = ' . $db->quote('1'));
// Create the base select statement.
$query->select('*')
->from($db->quoteName('#__table'))
->where($db->quoteName('state') . ' = ' . $db->quote('1'))
->where($db->quoteName('subCheckIn') . ' IN (' . $subQuery . ')')
->order($db->quoteName('ordering') . ' ASC');
// Set the query and load the result.
$db->setQuery($query);
try
{
$result = $db->loadObjectList();
}
catch (RuntimeException $e)
{
throw new RuntimeException($e->getMessage(), $e->getCode());
}
// Or write Inline subquery this way
$query->select('*')
->from($db->quoteName('#__table'))
->where($db->quoteName('state') . ' = ' . $db->quote('1'))
->where($db->quoteName('subCheckIn') . ' IN (' . function(){
return $db->getQuery(true)
->select('subCheckIn')
->from($db->quoteName('#__sub_table'))
->where($db->quoteName('subTest') . ' = ' . $db->quote('1'))
} . ')')
->order($db->quoteName('ordering') . ' ASC');
By 6|_||\|74|\| |>4731
Cool! Thanks! Follows K.I.S.S principle. Simple is beautiful. Nice one! Have a nice day