How to select a blank(dummy) column in a JDatabse UNION query

by Hannah Smith   Last Updated April 20, 2015 23:04 PM

I have two queries that I am combining using a UNION statement. I know that I need both queries to get the same number and type of arguments to work.

I have one query that only really needs three fields and one that needs four.

Eg query 1's select line looks like this

->select ($db->quoteName(array('c.event','b.date','b.type','a.mob')))

query 2's select line looks like this, XX denotes where I need to insert a dummy field:

->select ($db->quoteName(array('b.event','a.date','a.type', XX)))

What the syntax for putting a dummy field into the select statement of the second query please?

Tags : mysql jdatabase


Answers 1


I haven't tested it (short on time), but I think this should add a dummy column b.mob which is filled with string 'dummy'.

->select ($db->quoteName(array('b.event','a.date','a.type')))
->select ($db->quote('dummy'). ' AS ' . $db->quoteName('b.mob'))

The equivalent sql should be

SELECT `b.event`, `a.date`, `a.type`, 'dummy' AS `b.mob`
user3154108
user3154108
April 21, 2015 13:13 PM

Related Questions



PHP function with JDatabase queries

Updated September 08, 2016 08:06 AM

Ordering a UNION

Updated April 21, 2015 00:04 AM

Transforming a Query for JDATABASE

Updated July 28, 2015 14:04 PM