What is the correct way to perform this query? Additionally, I'd like to trim spaces from fullname, because if middle is empty it still returns the spaces before and after it.
SELECT first,middle,last,
CONCAT(first,' ',middle,' ',last) AS fullname
FROM names a
LEFT JOIN info b ON fullname = b.name
LIMIT 1
the current error is: ERROR 1054 (42S22): Unknown column 'fullname' in 'on clause'
CONCAT(first, COALESCE(CONCAT(' ', middle, ' '), ' '), last) AS fullnamefor the fullname