Unconfirmed, but this hack should work ...
SELECT * FROM ( SELECT profile.id AS id, given.name AS 'given_name', family.name AS 'family_name' FROM green_profile profile LEFT JOIN green_name given ON given.profileid = profile.id AND given.name_typeid = 0 LEFT JOIN green_name family ON family.profileid = profile.id AND family.name_typeid = 1 ) as temptable WHERE given_name LIKE 'levi%' ORDER BY given_name DESC LIMIT 0 , 25
It works by simply creating a temporary table from your original select statement (without the where and ordering clause), which indicates the columns you specify. Then you select the desired column names from it.
A better approach would be to create a view with the desired column names and select from the view ...
CREATE VIEW newtable AS SELECT profile.id AS id, given.name AS 'given_name', family.name AS 'family_name' FROM green_profile profile LEFT JOIN green_name given ON given.profileid = profile.id AND given.name_typeid = 0 LEFT JOIN green_name family ON family.profileid = profile.id AND family.name_typeid = 1;
And then...
SELECT * FROM newtable WHERE given_name LIKE 'levi%' ORDER BY given_name DESC LIMIT 0 , 25
source share