0

Good evening! I have a MYSQL problem that I can't figure out...

Here's my situation:

Table Name: up_categorys

ID | Category
--------------
5  | Xbox Live

When I do this query, the database returns zero rows:

SELECT id FROM up_categorys WHERE category_name = 'Xbox Live' LIMIT 0 , 30

But when I do this query, the database returns 1 row:

SELECT id FROM up_categorys WHERE category_name LIKE '%Xbox Live%' LIMIT 0 , 30

Maybe a genius can solve this? Maybe you!

4
  • 2
    Are you sure Row ID 5 is exactly 'Xbox Live' and doesn't have any spaces or anything before or after? Commented Jul 2, 2013 at 22:13
  • 1
    What about SELECT id FROM up_categorys WHERE category_name LIKE 'Xbox Live' LIMIT 0 , 30 or SELECT id FROM up_categorys WHERE category_name LIKE 'Xbox Live%' LIMIT 0 , 30 or SELECT id FROM up_categorys WHERE category_name LIKE '%Xbox Live' LIMIT 0 , 30. Does any of these queries return something? Commented Jul 2, 2013 at 22:13
  • can you try to SELECT id FROM up_categorys WHERE TRIM(category_name) = 'Xbox Live'? what do you get? Commented Jul 2, 2013 at 22:17
  • I'd also try SELECT length(category_name) FROM up_categorys WHERE category_name LIKE '%Xbox Live%' to make sure the value has the expected 9 characters. Commented Jul 2, 2013 at 22:17

1 Answer 1

2

You might have leading or trailing blanks in the category_name field.
Try

SELECT id FROM up_categorys WHERE TRIM(category_name) = 'Xbox Live' LIMIT 0 , 30
Sign up to request clarification or add additional context in comments.

1 Comment

The problem was indeed the trailing blanks. Thanks for saving me 2 hours of my life ;-)!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.