Skip to content Skip to sidebar Skip to footer

Sql Users Searching Query

I would like to create query to search given information in table users. Table consists: of id, username, firstname, lastname, phone and email. Sample search text: mat h 50 @l d Th

Solution 1:

I think this should do it:

SELECT*FROM  `users` WHERE (
       (firstname LIKE'%mat%'OR lastname LIKE'%mat%'OR
        phone LIKE'%mat%'OR email LIKE'%mat%'OR username LIKE'%mat%')
       AND
       (firstname LIKE'%h%'OR lastname LIKE'%h%'OR
        phone LIKE'%h%'OR email LIKE'%h%'OR username LIKE'%h%')
       AND
       (firstname LIKE'%50%'OR lastname LIKE'%50%'OR
        phone LIKE'%50%'OR email LIKE'%50%'OR username LIKE'%50%')
       AND
       (firstname LIKE'%@l%'OR lastname LIKE'%@l%'OR
        phone LIKE'%@l%'OR email LIKE'%@l%'OR username LIKE'%@l%')
       AND
       (firstname LIKE'%d%'OR lastname LIKE'%d%'OR
        phone LIKE'%d%'OR email LIKE'%d%'OR username LIKE'%d%')
      )

You need to test each criteria separately, not each field.

Post a Comment for "Sql Users Searching Query"