我喜欢在where子句中组合两列:
$stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees WHERE (firstname + ' ' + lastname) LIKE :username');
这是我得到的错误:
解析错误:语法错误,意外''。姓氏)LIKE:用户名'' (T_CONSTANT_ENCAPSED_STRING)
我可以在firstname
和lastname
之间添加空格吗?
感谢您的帮助!
答案 0 :(得分:3)
您可以使用CONCAT()
功能
$stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees
WHERE CONCAT(firstname, ' ', lastname) LIKE :username');
答案 1 :(得分:0)
$stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees
WHERE CONCAT(CONCAT(firstname, ' '), lastname) LIKE :username');
如果firstname和lastname是char类型,则使用rtrim函数