Difference between LIKE and = operator
For query with sql, how do you select all the records from a table named "persons" where the value of the column "firstname" is "peter"? 1 select * from persons where firstname like 'peter' 2 select * from persons where firstname='peter' 3 select [all] from persons where firstname='peter' 4select [all] from persons where firstname like 'peter' whats the correct ans.
Re: Difference between LIKE and = operator
[QUOTE=ashalalaxmi2002;28316]For query with sql, how do you select all the records from a table named "persons" where the value of the column "firstname" is "peter"? 1 select * from persons where firstname like 'peter' 2 select * from persons where firstname='peter' 3 select [all] from persons where firstname='peter' 4select [all] from persons where firstname like 'peter' whats the correct ans.[/QUOTE]
select * from persons where firstname like 'peter'
select * from persons where firstname='peter'
You know the exact name then no need to use like operator. Better to use =.
Like is used for pattern search.
If you want to know the list of all persons whose firstname starts with peter then use like operator
select * from persons where firstname like 'peter%'
Re: Difference between LIKE and = operator
select * from persons where firstname='peter'
Re: Difference between LIKE and = operator
If you know the exact value to check then you can use the operator '=' else you can use like operator if some part in the search condition known.
If you know the exact value then better to use '=' instead of like
Re: Difference between LIKE and = operator
[QUOTE=ashalalaxmi2002;28316]For query with sql, how do you select all the records from a table named "persons" where the value of the column "firstname" is "peter"? 1 select * from persons where firstname like 'peter' 2 select * from persons where firstname='peter' 3 select [all] from persons where firstname='peter' 4select [all] from persons where firstname like 'peter' whats the correct ans.[/QUOTE]
Before u r writing these type of queries, remember one point.
In case of Like condition u have top mention '%' symbol, For Ex.
[COLOR="Magenta"] select * from persons where firstname like 'Peters%';[/COLOR]
In case of = condition u have no need to mention any thing but u have to give Exact value for that field, For Ex.
[COLOR="Red"]select * from persons where firstname = 'Peters';[/COLOR]
If the data is with that same name, the data will display.
I think it's correct answer for ur query.
Re: Difference between LIKE and = operator
Both "=" and "like" operator are use to search the data within table. But "=" operator are usede when you are confident about the inputs you have given bcoz query will search that specific value in the table if it will get it will display output otherwise......no output will be there but if you are using like '****%" operator then it will be searching for all the data that are matching your inputs... Enjoy..........
Thanks
rajiv gupta
yogik technologies pvt. Ltd.