perlfan
perlfan

Reputation: 11

Adding space when combining 2 columns in where clause

I like to combine two columns in my where clause:

$stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees WHERE (firstname + ' ' + lastname) LIKE :username');

This is the error I get:

Parse error: syntax error, unexpected '' . lastname) LIKE :username'' (T_CONSTANT_ENCAPSED_STRING)

Is there a way I can add a space in between firstname and lastname?

Thanks for help!

Upvotes: 1

Views: 53

Answers (2)

Adesh
Adesh

Reputation: 34

 $stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees 
WHERE CONCAT(CONCAT(firstname, ' '), lastname)  LIKE :username');

if firstname and lastname is of char type, then use rtrim function

Upvotes: 0

Sachu
Sachu

Reputation: 7766

You can use CONCAT() function

    $stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees 
WHERE CONCAT(firstname, ' ', lastname)  LIKE :username');

Upvotes: 3

Related Questions