busboy
1
My users are stored in the database with a firstname lastname. For this project I need to be able to search on their full name like, “David Jones”.
I’ve used concat a little bit to produce a full name in the query results, but is the same thing possible when searching?
Thanks!
donboe
2
SELECT
concat( firstName, ' ', lastName ) AS fullName
FROM yourTable
WHERE fullName LIKE ......
busboy
3
#1054 - Unknown column ‘fullName’ in ‘where clause’
r937
4
yeah, you can’t use a SELECT clause column alias in the WHERE clause
you have to do this –
SELECT CONCAT( firstName, ' ', lastName )
AS fullName
FROM yourTable
WHERE CONCAT( firstName, ' ', lastName ) LIKE ...
alternatively, this –
SELECT fullName
FROM ( SELECT CONCAT( firstName, ' ', lastName )
AS fullName
FROM yourTable ) AS d
WHERE fullName LIKE ...
donboe
5
Oops my wrong! Thanks rudy