dbTalk Databases Forums  

Strange problem with MySQL string comparison

comp.databases comp.databases


Discuss Strange problem with MySQL string comparison in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jammypodger
 
Posts: n/a

Default Strange problem with MySQL string comparison - 06-05-2008 , 06:48 AM






I have been using MySQL on and off for a number of years but I am
stumped by this problem.

I am doing a select which requires a join to a second table using an
account key, I have a WHERE clause which ensures that I only get the
correct type of account.
Basically the type of account is 'CUSTOMER' but if I use the code

....
WHERE ACCOUNT.TYPE="CUSTOMER"
....

Then I get no matches.
However, if I use

....
WHERE STRCMP(ACCOUNT.TYPE,"CUSTOMER")=0
....

Then I get matches as expected.

Could anyone explain why I get a result set with a STRCMP match, but
not with the equals operator?

TIA

Reply With Quote
  #2  
Old   
jammypodger
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 06:58 AM






I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

....
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
....

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.

Reply With Quote
  #3  
Old   
jammypodger
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 06:58 AM



I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

....
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
....

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.

Reply With Quote
  #4  
Old   
jammypodger
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 06:58 AM



I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

....
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
....

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.

Reply With Quote
  #5  
Old   
David Cressey
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 07:10 AM




"jammypodger" <rick (AT) fourfront (DOT) ltd.uk> wrote

Quote:
I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

...
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
...

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.
It sounds like a problem with padding and/or trimming blanks. What does
MySQL doc say about testing strings of different lengths for equality?




Reply With Quote
  #6  
Old   
David Cressey
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 07:10 AM




"jammypodger" <rick (AT) fourfront (DOT) ltd.uk> wrote

Quote:
I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

...
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
...

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.
It sounds like a problem with padding and/or trimming blanks. What does
MySQL doc say about testing strings of different lengths for equality?




Reply With Quote
  #7  
Old   
David Cressey
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 07:10 AM




"jammypodger" <rick (AT) fourfront (DOT) ltd.uk> wrote

Quote:
I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

...
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
...

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.
It sounds like a problem with padding and/or trimming blanks. What does
MySQL doc say about testing strings of different lengths for equality?




Reply With Quote
  #8  
Old   
jammypodger
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 07:35 AM



On Jun 5, 1:10*pm, "David Cressey" <cresse... (AT) verizon (DOT) net> wrote:
Quote:
"jammypodger" <r... (AT) fourfront (DOT) ltd.uk> wrote in message

news:eddca4b9-b026-4864-8cef-5a135a53598e (AT) e39g2000hsf (DOT) googlegroups.com...

I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

...
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
...

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.

It sounds like a problem with padding and/or trimming blanks. *What does
MySQL doc say about testing strings of different lengths for equality?
Field length is 8 characters so no space for blanks


Reply With Quote
  #9  
Old   
jammypodger
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 07:35 AM



On Jun 5, 1:10*pm, "David Cressey" <cresse... (AT) verizon (DOT) net> wrote:
Quote:
"jammypodger" <r... (AT) fourfront (DOT) ltd.uk> wrote in message

news:eddca4b9-b026-4864-8cef-5a135a53598e (AT) e39g2000hsf (DOT) googlegroups.com...

I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

...
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
...

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.

It sounds like a problem with padding and/or trimming blanks. *What does
MySQL doc say about testing strings of different lengths for equality?
Field length is 8 characters so no space for blanks


Reply With Quote
  #10  
Old   
jammypodger
 
Posts: n/a

Default Re: Strange problem with MySQL string comparison - 06-05-2008 , 07:35 AM



On Jun 5, 1:10*pm, "David Cressey" <cresse... (AT) verizon (DOT) net> wrote:
Quote:
"jammypodger" <r... (AT) fourfront (DOT) ltd.uk> wrote in message

news:eddca4b9-b026-4864-8cef-5a135a53598e (AT) e39g2000hsf (DOT) googlegroups.com...

I should add that the ACCOUNT.TYPE field is upper case.

Further to the above, if I use a query containing the following;-

...
WHERE LEFT(ACCOUNT.TYPE,8)="CUSTOMER"
...

Then I get all expected matches for the query.

The only thing that does not work is the direct comparison using the
equals operator.

btw. Version of MySQL is 5.0.27 running on Fedora Core 5.

It sounds like a problem with padding and/or trimming blanks. *What does
MySQL doc say about testing strings of different lengths for equality?
Field length is 8 characters so no space for blanks


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.