Geeks Talk

Prepare for your Next Interview




Difference between LIKE and = operator

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 ...


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-28-2008
Contributing Member
 
Join Date: Sep 2007
Location: hyderabad
Posts: 37
Thanks: 5
Thanked 2 Times in 2 Posts
ashalalaxmi2002 is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to ashalalaxmi2002 For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 03-29-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
Re: Difference between LIKE and = operator

Quote:
Originally Posted by ashalalaxmi2002 View Post
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.
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%'
Reply With Quote
The Following User Says Thank You to krishnaindia2007 For This Useful Post:
  #3 (permalink)  
Old 04-22-2008
Junior Member
 
Join Date: Jan 2008
Location: India
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
antonyfernando is on a distinguished road
Re: Difference between LIKE and = operator

select * from persons where firstname='peter'
Reply With Quote
  #4 (permalink)  
Old 07-17-2008
Junior Member
 
Join Date: Apr 2008
Location: Hyderabad
Posts: 28
Thanks: 1
Thanked 4 Times in 2 Posts
nageshkota is on a distinguished road
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
Reply With Quote
  #5 (permalink)  
Old 08-08-2008
Junior Member
 
Join Date: Jul 2008
Location: Bengaluru
Posts: 6
Thanks: 0
Thanked 3 Times in 3 Posts
ravikumar.drk is on a distinguished road
Re: Difference between LIKE and = operator

Quote:
Originally Posted by ashalalaxmi2002 View Post
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.
Before u r writing these type of queries, remember one point.

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.
Reply With Quote
  #6 (permalink)  
Old 08-30-2008
Junior Member
 
Join Date: Aug 2008
Location: KOLKATA
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
rajivgupta780184 is on a distinguished road
Smile 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.
Reply With Quote
Reply

  Geeks Talk > Databases > SQL


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 12:32 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved