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 &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
>
>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. |
|
|||
|
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 |
|
|||
|
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 = |
|
|||
|
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 |
|
|||
|
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 ================== |
|
|||
|
== 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 |