6

Like it said on the title, as we use alias to fields with a static query, i want to do same thing with a dynamic query

example :

with static select : $sql = db_query ("SELECT my_super_long_field as mslf FROM {super_long_table} as slt")

How to perform same with a db_select query please ?

$sql = db_select ('super_long_table','slt')
->fields('slt',array('mys_super_long_field', 'here i want alias for long fields')

Thank you

18

Use addField(). Here's an example:

$query = db_select('super_long_table', 'slt');
$query->addField('slt', 'mys_super_long_field', 'mslf');

Arguments passed to addField() are:

  • Table alias
  • Field - your long field name will be here
  • Alias - your short field alias will be here

Read more about it here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.