Solved

MySQL Oddity

Posted on 2014-12-02
10
109 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
  • 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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 83

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mySql Syntax 7 54
put constant from select to insert into field  Posgresql 2 89
MySQL ERROR 1045 (28000) 2 81
MSSQL 2008 with mySQL webservers 7 53
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikipedia.org/wiki/PHP  Very powerful.  But a…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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