0

I can't explain this. What fundamental thing am I overlooking which is causing this not to work? I have a simple table with only one entry (for testing purposes) at the moment:

TABLE votes
vote_id | user_id | image_id | vote_type 
----------------------------------------
43      | 8       | 5        | 1

Where vote_id is a primary key, user_id & image_id are foreign keys, and vote_type is a boolean

This ridiculously simple select query with 2 WHERE clauses won't even return the one entry in the table:

SELECT * FROM `votes` WHERE 'user_id' = 8 AND 'image_id' = 5;

Even 1 WHERE clause doesn't return anything:

SELECT * FROM `votes` WHERE 'vote_type' = 1;

Yet, a SELECT with no conditions does return the 1 result:

SELECT * FROM `votes`;

Note, I don't get any errors, I just get told that "MySQL returned an empty result set". What's going on here?

2
  • Could it be your columns aren't of integer type? Commented Aug 17, 2013 at 23:01
  • Make sure the fields are string, if they are, use quotation marks in the query. SELECT * FROM 'votes' WHERE 'user_id' = '8' AND 'image_id' = '5'; Commented Aug 17, 2013 at 23:01

1 Answer 1

2

You need backquotes instead of single quotes. Try:

SELECT * FROM `votes` WHERE `user_id` = 8 AND `image_id` = 5;

Single quotes are used for string constants. So the string "user_id" is not equal to the integer "8".

Sign up to request clarification or add additional context in comments.

Comments

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.