How to use UNION query with jDatabase

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

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
mousebat
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Thu Aug 23, 2012 9:30 am

How to use UNION query with jDatabase

Post by mousebat » Wed Nov 20, 2013 2:24 pm

Hi

This is a good one - can't seem to find an example of how to use

Code: Select all

$query->union
in getListQuery. At the moment I'm doing it old school and having to write the whole query out in the

Code: Select all

$query
variable.

I want to select similar data from different tables and use the join function that now exists in the query object.

SELECT field1,field2 FROM `#__mycomponent_table1` where field1 = 0
UNION
SELECT field1,field2 FROM `#__mycomponent_table2` where field1 = 0

etc...

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 22115
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, The Netherlands
Contact:

Re: How to use UNION query with jDatabase

Post by pe7er » Wed Nov 20, 2013 4:08 pm

Check Joomla 3.2 /administrator/components/com_finder/helpers/indexer/query.php line 1269-1296

The union function is defined in the library file: /libraries/joomla/database/query.php line 1540
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
Co-developer of d2 Content https://data2site.com/joomla-extensions/d2-content

alwarren
Joomla! Guru
Joomla! Guru
Posts: 527
Joined: Fri Aug 19, 2005 9:27 am

Re: How to use UNION query with jDatabase

Post by alwarren » Wed Nov 20, 2013 9:12 pm

I haven't been able to get union to work at all using query objects. It seems to be buggy. There are some tracker items about it.
Al Warren
This ain't my first rodeo. Red Foreman says it best.
CQDX de WR5AW

sravanvaranasi
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Sun Oct 06, 2013 2:13 pm

Re: How to use UNION query with jDatabase

Post by sravanvaranasi » Wed Feb 19, 2014 6:07 am

Thanks a lot pe7er. That worked for me.

User avatar
Bakual
Joomla! Guru
Joomla! Guru
Posts: 835
Joined: Sun Dec 13, 2009 9:00 pm
Location: Switzerland
Contact:

Re: How to use UNION query with jDatabase

Post by Bakual » Tue Mar 04, 2014 8:43 pm

There is a PR for this: https://github.com/joomla/joomla-cms/pull/2735

Testing welcome ;)


Locked

Return to “Joomla! 3.x Coding”