Database Query with JDatabase Object

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
sazbaztaz
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Mar 18, 2010 2:20 pm

Database Query with JDatabase Object

Post by sazbaztaz » Wed Jun 29, 2016 12:39 pm

Hi I have the following regular SQL Query...

Code: Select all

			$query = 'SELECT  a.*
			FROM  yyf3h_bmzr_staff a
			INNER JOIN
			(
				SELECT  clientid, staffid, COUNT(*) totalCount
				FROM    yyf3h_bmzr_relations
				WHERE franchiseeid = ' . $owner . '
				AND status < 9
				GROUP   BY staffid
				having count(case when clientid = ' . $clientid . ' then 1 end) = 0
			) b ON  a.id = b.staffid
			WHERE a.owner = ' . $owner . '
			AND a.status < 9
			AND a.name LIKE \'%' . $search . '%\'
			';
How would this look like using the proper JDatabase object like so...

Code: Select all

		$db =& JFactory::getDBO();
		$q =& $db->getQuery(true);
		$q->select(array('a.*'));
		$q->from($this->db->quoteName('#__bmzr_staff', 'a'));
My problem is that there is another select statement WITHIN the join and I can't find any complex Joomla query examples out there.
Thank you!

itoctopus
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4025
Joined: Mon Nov 25, 2013 4:35 pm
Location: Montreal, Canada
Contact:

Re: Database Query with JDatabase Object

Post by itoctopus » Fri Jul 01, 2016 12:16 am

Please check components/com_content/models/articles.php - there are inner queries there which should be an excellent guide on how to do that (I think there is an inner query for generating the badcats).
http://www.itoctopus.com - Joomla consulting at its finest
https://twitter.com/itoctopus - Follow us on Twitter

sazbaztaz
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Mar 18, 2010 2:20 pm

Re: Database Query with JDatabase Object

Post by sazbaztaz » Fri Jul 01, 2016 7:19 am

That is actually a good idea. Will do that thank you!


Locked

Return to “Joomla! 3.x Coding”