skip to Main Content

I have a mysql column(name) with some text like this "firstname middlename surname lastname".
How can i select that row with a query like

SELECT name FROM client WHERE name like %firstname lastname%

. The where clause comes from a single html input text.

3

Answers


  1. Could you use

    select name from client where name like '%firstname%' and name like '%lastname%'
    
    Login or Signup to reply.
  2. You can search by separating the words in two where argumants

     SELECT name FROM client WHERE name like '%firstname%' AND  name like '%lastname%'
    
    Login or Signup to reply.
  3. If you want it the way you asked, you could do it like this

    SELECT name FROM client WHERE name LIKE 'John% %Doe'
    

    So if in your table at the field "name" you have a value that is "John Fidzerald Mayhem Doe", it will be selected

    But if I can advice you, create a column for each value you want, so a column for firstName which would not be nullable, a column for middlename which would be nullable, a column for surname which would be also nullable and a column for lastname which wouldn’t be nullable

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search