Reputation: 86
How can I search a keyword in multiple columns in mysql syntax?
Now I have a variable $phone
, that store the form input, and use the syntax to search in a single column:
SELECT * FROM db.table WHERE 'phone1' = '".$phone."';
How I make that search through columns 'phone1', 'phone2', 'phone3' and 'phone4'?
Thanks
Upvotes: 0
Views: 1084
Reputation: 14361
Why not try in
: =)
SELECT *
FROM db.table
WHERE '".$phone."' in (`phone1`, `phone3`, `phone3`, `phone4`)
;
Upvotes: 1
Reputation: 219894
Use OR
in your WHERE
clause
SELECT *
FROM db.table
WHERE 'phone1' = '".$phone."'
OR 'phone2' = '".$phone."'
OR 'phone3' = '".$phone."'
OR 'phone4' = '".$phone."'
Upvotes: 5