testing multiple conditions with like

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

testing multiple conditions with like

Post by timoteo »

Hi everyone,
I'm looking how to match a name field with 2 database columns

Code: Select all

SELECT id FROM username WHERE firstname LIKE %john% OR %smith% OR firstname IN ('john smith') AND lastname LIKE %john% OR %smith% OR lastname IN ('john smith')
Is this correct? I can't get a match on the second word. (smith) only on john. How can I get a match on the second word as well?
Thanks for any help.
timoteo
Forum Contributor
Posts: 125
Joined: Sat Jan 08, 2011 6:46 am

Re: testing multiple conditions with like

Post by timoteo »

resolved:
firstname LIKE %john% OR firstname LIKE %smith%...
Post Reply