Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Write subquery in Joomla 3 using JDatabase method.

Here is an example of write subquery in Joomla! 3 using JDatabase method.

// Initialize variables.
$db       = JFactory::getDbo();
$subQuery = $db->getQuery(true);
$query    = $db->getQuery(true);

// Create the base subQuery select statement.
	->where($db->quoteName('subTest') . ' = ' . $db->quote('1'));

// Create the base select statement.
	->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.

	$result = $db->loadObjectList();
catch (RuntimeException $e)
	throw new RuntimeException($e->getMessage(), $e->getCode());

By 6|_||\|74|\| |>4731

Copy link

AdamMadrzejewski commented May 12, 2015

Great! Thanks for this gist.

Copy link

AdamMadrzejewski commented Oct 20, 2015

Wow, somehow I returned here again and saw my comment! Great gist man ;)

Copy link

gunjanpatel commented Jul 6, 2016

Welcome @AdamMadrzejewski Glade that it is helpful to you.

Copy link

NhatNam98 commented Nov 26, 2018

Thanks Man , have a good day

Copy link

application2000 commented May 9, 2019

Cool! Thanks! Follows K.I.S.S principle. Simple is beautiful. Nice one! Have a nice day

Copy link

diguz commented Sep 26, 2019

Thanks! This is great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment