Bluehost.com Web Hosting $6.95

distinguish between "-" and "_"

This is a discussion on distinguish between "-" and "_" within the MySQL Database forums, part of the Database Forums category; Hello, When I run two different SQL requests, they return same result: SELECT part_number, description FROM part WHERE part_number LIKE &...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-21-2007
leileili@hotmail.com
 
Posts: n/a
Default distinguish between "-" and "_"

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

Reply With Quote
  #2 (permalink)  
Old 05-22-2007
Gordon Burditt
 
Posts: n/a
Default Re: distinguish between "-" and "_"

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


Reply With Quote
  #3 (permalink)  
Old 05-22-2007
leileili@hotmail.com
 
Posts: n/a
Default Re: distinguish between "-" and "_"

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

Reply With Quote
  #4 (permalink)  
Old 05-22-2007
Captain Paralytic
 
Posts: n/a
Default Re: distinguish between "-" and "_"

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 =

Reply With Quote
  #5 (permalink)  
Old 06-12-2007
Christopher Pomasl
 
Posts: n/a
Default Re: distinguish between "-" and "_"

On Mon, 21 May 2007 22:23:15 +0000, 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.


The underscore will match any one character.
The % will match any charcters including none.

So LIKE "000-1_GB-01"
will ok "000-1AGB-01"
or "000-1XGB-01"
etc A-the underscore matches ANYTHING in this position.


And LIKE "000-1%GB-01"
will ok "000-1GB-01"
or "000-1XGB-01"
or "000-1XYZGB-01"
etc A-the percent matches anything that STARTS in
this position, including nothing.

Chris


Reply With Quote
  #6 (permalink)  
Old 06-12-2007
Jerry Stuckle
 
Posts: n/a
Default Re: distinguish between "-" and "_"

Christopher Pomasl wrote:
> On Mon, 21 May 2007 22:23:15 +0000, 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.

>
> The underscore will match any one character.
> The % will match any charcters including none.
>
> So LIKE "000-1_GB-01"
> will ok "000-1AGB-01"
> or "000-1XGB-01"
> etc A-the underscore matches ANYTHING in this position.
>
>
> And LIKE "000-1%GB-01"
> will ok "000-1GB-01"
> or "000-1XGB-01"
> or "000-1XYZGB-01"
> etc A-the percent matches anything that STARTS in
> this position, including nothing.
>
> Chris
>
>


Chris,

To start with, get a handle on database design theory (it's not that
hard). Google for "database normalization". That should help get you
started.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #7 (permalink)  
Old 06-12-2007
lark
 
Posts: n/a
Default Re: distinguish between "-" and "_"

== Quote from Jerry Stuckle (jstucklex@attglobal.net)'s article
> Christopher Pomasl wrote:
> > On Mon, 21 May 2007 22:23:15 +0000, 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.

> >
> > The underscore will match any one character.
> > The % will match any charcters including none.
> >
> > So LIKE "000-1_GB-01"
> > will ok "000-1AGB-01"
> > or "000-1XGB-01"
> > etc A-the underscore matches ANYTHING in this position.
> >
> >
> > And LIKE "000-1%GB-01"
> > will ok "000-1GB-01"
> > or "000-1XGB-01"
> > or "000-1XYZGB-01"
> > etc A-the percent matches anything that STARTS in
> > this position, including nothing.
> >
> > Chris
> >
> >

> Chris,
> To start with, get a handle on database design theory (it's not that
> hard). Google for "database normalization". That should help get you
> started.


here's a good start from mysql's website:

http://dev.mysql.com/tech-resources/...alization.html
--
POST BY: lark with PHP News Reader
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:01 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0