Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Suche nach verkettetem Feld

SELECT *
FROM 
    (
    SELECT `users`.`firstname`, `users`.`lastname`, `users`.`id`, 
    CONCAT(firstname," " ,lastname) AS `firstnamelastname`, 
    CONCAT(lastname," " ,firstname) AS `lastnamefirstname` 
    FROM `users` 
    WHERE (id != '15')
)
WHERE (firstnamelastname like 'a%' ) 
OR (lastnamefirstname like 'a%')

Ihre Aliase stehen MySQL nicht zur Verfügung, wenn es zum ersten Mal WHERE auswertet Klausel.

Aber Ihre Abfrage entspricht tatsächlich dieser:

SELECT `users`.`firstname`, `users`.`lastname`, `users`.`id`, 
CONCAT(firstname," " ,lastname) AS `firstnamelastname`, 
CONCAT(lastname," " ,firstname) AS `lastnamefirstname` 
FROM `users` 
WHERE (id != '15')
AND (firstname LIKE 'a%' OR lastname LIKE 'a%')

Ihr concat in der where-Klausel ist also unnötig.