Prepare for your Next Interview
This is a discussion on Difference between LIKE and = operator within the SQL forums, part of the Databases category; 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 ...
|
|||
|
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.
|
| The Following User Says Thank You to ashalalaxmi2002 For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: Difference between LIKE and = operator
Quote:
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%' |
| The Following User Says Thank You to krishnaindia2007 For This Useful Post: | ||
|
|||
|
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:
In case of Like condition u have top mention '%' symbol, For Ex. select * from persons where firstname like 'Peters%'; In case of = condition u have no need to mention any thing but u have to give Exact value for that field, For Ex. select * from persons where firstname = 'Peters'; If the data is with that same name, the data will display. I think it's correct answer for ur query. |
|
|||
|
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IN operator in Oracle SQL | ily_saravanan | SQL | 1 | 03-29-2008 01:15 AM |
| C++ Operator Overloading Part II | Lokesh M | C and C++ | 1 | 12-28-2007 02:21 AM |
| Using LIKE operator in multiple condition | Sant_parkash | SQL | 4 | 11-29-2007 02:47 AM |
| Operator OverLoading Code | vinodjallapally | Java | 1 | 08-31-2007 07:45 AM |
| Operator Overloading | sripri | C and C++ | 2 | 12-11-2006 10:12 AM |