?
Solved

MySQL Oddity

Posted on 2014-12-02
10
Medium Priority
?
119 Views
Last Modified: 2014-12-11
See attached. The tables is small contains 25 rows.

If I do this query: "SELECT * from part_codes where cdesc = 'Favorites'" I get zero rows.

If I do "SELECT * from part_codes where cdesc like  'Favorites%'" I get the expected result.

Why can't it do something as simple as this?
part-codes-table.jpg
pc-select-equal.jpg
pc-select-like.jpg
0
Comment
Question by:Richard Korts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40477592
Are you sure you don't have any spaces in the Favourites cell?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40477593
Does it work with this

"SELECT * from part_codes where TRIM(cdesc) = 'Favorites'" 

Open in new window

0
 

Author Comment

by:Richard Korts
ID: 40477597
It DOES NOT work with this:  SELECT * from part_codes where TRIM(cdesc) = 'Favorites'

Returns zero rows.

If there are spaces, they are at the trailing end; I have built HUNDREDS of SQL like this, never an issue.

I can go with the like & put a % at the end but I can't understand why it doesn't work in such a SIMPLE case.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:Richard Korts
ID: 40477604
Is cdesc a reserved word in MySQL?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40477605
No.

Can you do a dump of the table and attach here, there could be invisible characters like a CR in the field
0
 

Author Comment

by:Richard Korts
ID: 40477620
I can;t see how to do a dump, it doesn't seem to give that option in phpMySQL. See attached.
phpmysql-ops.jpg
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40477627
Yes, it does.  Click on the Export tab.
0
 

Author Comment

by:Richard Korts
ID: 40477639
OK, attached.
part-codes.sql
0
 

Author Comment

by:Richard Korts
ID: 40477642
FYI, I solved my immediate need using like & the full string followed with %

Crazy!!
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40477644
All your fields have a carriage return in the value
So a slight amendment to my earlier sql

"SELECT * from part_codes where TRIM(TRAILING '\n' FROM cdesc) = 'Favorites'" 

Open in new window


Though better to remove it before inserting it into the db
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question