Results 1 to 6 of 6

Thread: Difference between LIKE and = operator

  1. #1
    Contributing Member
    Join Date
    Sep 2007
    Answers
    35

    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.


  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    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%'


  3. #3
    Junior Member
    Join Date
    Jan 2008
    Answers
    4

    Re: Difference between LIKE and = operator

    select * from persons where firstname='peter'


  4. #4
    Contributing Member
    Join Date
    Apr 2008
    Answers
    31

    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


  5. #5
    Junior Member
    Join Date
    Jul 2008
    Answers
    8

    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.


  6. #6

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact