Reputation: 16029
I'm new to database and querying in MySql. I have a table in my database with id, fistname, middlename and lastname. In my webapp, I have a search box so that I can search my database using the firstname, middlename and lastname and it will display the result in my web app. Do I need to use SELECT statement to do this and what condition should I query?
Please advise.
Many thanks.
Upvotes: 0
Views: 2955
Reputation: 10214
select id, firstname, middlename, lastname where firstname like '%searchterm%' or middlename like '%searchterm%' or lastname like '%searchterm%'
this will give you a very broad result, as it matches on the search term anywhere within any of the name fields.
you can also use 'searchterm%' to match ones starting with the searchteam, and 'searchterm' for an exact match
Upvotes: 2