Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
distinguish between "-" and "_"
Old
  (#1)
Guest
Guest
 
Posts: n/a
Default distinguish between "-" and "_" - 06-04-2007, 07:58 AM

Hello,

When I run two different SQL requests, they return same result:

SELECT part_number, description FROM part WHERE part_number LIKE
"000-1_GB-01"

and

SELECT part_number, description FROM part WHERE part_number LIKE
"000-1-GB-01"

I expect the first one returns "not found" since there's no
"000-1_GB-01"
in the part table, only "000-1-GB-01". but both returns "000-1-GB-01".
Can anyone please tell me why?
where should I go to find the course ?
Thanks in advance.

Lei

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: distinguish between "-" and "_"
Old
  (#2)
Gordon Burditt
Guest
 
Posts: n/a
Default Re: distinguish between "-" and "_" - 06-04-2007, 07:58 AM

>
>When I run two different SQL requests, they return same result:
>
>SELECT part_number, description FROM part WHERE part_number LIKE
>"000-1_GB-01"
>
>and
>
>SELECT part_number, description FROM part WHERE part_number LIKE
>"000-1-GB-01"


Were you aware that _ is a wildcard character, so your first query
could match "000-1QGB-01"? Solution: if you want a literal _, escape
it.


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: distinguish between "-" and "_"
Old
  (#3)
Guest
Guest
 
Posts: n/a
Default Re: distinguish between "-" and "_" - 06-04-2007, 07:58 AM

On May 21, 3:23 pm, gordonb.vr...@burditt.org (Gordon Burditt) wrote:
> >When I run two different SQL requests, they return same result:

>
> >SELECT part_number, description FROM part WHERE part_number LIKE
> >"000-1_GB-01"

>
> >and

>
> >SELECT part_number, description FROM part WHERE part_number LIKE
> >"000-1-GB-01"

>
> Were you aware that _ is a wildcard character, so your first query
> could match "000-1QGB-01"? Solution: if you want a literal _, escape
> it.


I didn't know that. Thanks for your information. -Lei

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: distinguish between "-" and "_"
Old
  (#4)
Captain Paralytic
Guest
 
Posts: n/a
Default Re: distinguish between "-" and "_" - 06-04-2007, 07:58 AM

On 21 May, 23:23, gordonb.vr...@burditt.org (Gordon Burditt) wrote:
> >When I run two different SQL requests, they return same result:

>
> >SELECT part_number, description FROM part WHERE part_number LIKE
> >"000-1_GB-01"

>
> >and

>
> >SELECT part_number, description FROM part WHERE part_number LIKE
> >"000-1-GB-01"

>
> Were you aware that _ is a wildcard character, so your first query
> could match "000-1QGB-01"? Solution: if you want a literal _, escape
> it.


And don't use LIKE where it is not needed. In this situation you
should use =

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top