0

In a Zend_Db_Select object, I am doing a join to get user information for some data records. For the join is on a userId, I would like to combine the user first and last name into a single column of name.

Basically I am looking to have something similar to this:

$table = array('u' => 'User');
$condition = 'u.id = t.id';
$columns = array('UserName' => 'u.FirstName + " " + u.LastName')
$select->joinLeft($table, $condition, $columns);

I have tried using a Zend_Db_Expr with no luck and the above does not work.

How would I go about doing this?

2
  • It seems that you've a trailing single quot here ---> 'u.FirstName Commented Jan 17, 2013 at 22:26
  • If I remember it good, concatenation isn't a standard operation. So, every DBMS use it in a different way (for example ||). What DBMS underlay Zend_Db? Have you checked that you're using the right concatenation method? Commented Jan 17, 2013 at 22:52

1 Answer 1

1

Zend_Db_Expr is the way to go, but you'll have better luck if you use the database's concatenation function. Assuming MySQL:

$columns = new Zend_Db_Expr("CONCAT(u.FirstName, ' ', u.LastName') AS name")
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I wasn't using the proper concatenation function when creating the Zend_Db_Expr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.