0

P.S, I'm sorry if my English is bad. P.P.S, please mark if this question is duplicate.

I have a MySQL query here where I can use the AS clause in order to find the specific name. Here's my code below:

SELECT CONCAT(students.FirstName, ' ', students.LastName) AS FullName 
FROM `students` WHERE FullName LIKE '%john%'

Buy MySQL returned like this:

#1054 - Unknown column 'FullName' in 'where clause'

How can I achieve this one in order for FullName to find what they want?

T.S.
  • 18,195
  • 11
  • 58
  • 78
jhenryj09
  • 45
  • 8
  • 1
    Did you try changing the where clause to `WHERE CONCAT(students.FirstName, ' ', students.LastName) LIKE '%john%'` ? – Salvino D'sa Oct 17 '21 at 05:00

1 Answers1

1

Fullname is an alias that you just gave to your "column". It does not exist in DB. If you want to search by "full name" in WHERE, you need to repeat the exercise there

WHERE CONCAT(students.FirstName, ' ', students.LastName) LIKE '%john%'

Optionally, you can pre-built inline view and then fullname will become a thing

SELECT * 
FROM
(
    SELECT
        CONCAT(students.FirstName, ' ', students.LastName) AS FullName
    FROM
        `students`
) inlineView
WHERE 
    FullName LIKE '%joe%' 
T.S.
  • 18,195
  • 11
  • 58
  • 78