Search code examples
joomla

Joomla database query SELECT AS


So I'm just hypothetically thrilled to be querying my hypothetical database:

$query->select($db->quoteName(array('user_id', 'name')));

I would, however, like the query to look like:

SELECT `user_id` AS `uid`, `name` AS `User-Name`

How the heck do I get the AS in there?


Solution

  • I know this question is 6 months old, so you've probably found an answer or worked around it, but for anyone else who has a similar problem:

    $query->select($db->quoteName(array('user_id','name'),array('uid','User-Name')));
    

    If you only want to use an alias for some fields, just pass null in the array for the fields you don't want to alias, so for example:

    $query->select($db->quoteName(array('user_id','name'),array(null,'User-Name')));
    

    would give

    "SELECT `user_id`, `name` AS `User-Name`"