简单选择查询返回空结果集?

时间:2022-08-28 23:32:01

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

vote_id是一个主键,user_id & image_id是外键,vote_type是一个布尔值?

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

这个非常简单的select查询,其中有两个WHERE子句甚至不能返回表中的一个条目:

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

Even 1 WHERE clause doesn't return anything:

甚至1 WHERE子句没有返回任何东西:

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

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

然而,没有条件的选择返回1结果:

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?

注意,我没有任何错误,我只是被告知“MySQL返回一个空结果集”。这是怎么回事?

1 个解决方案

#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".

单引号用于字符串常量。因此,字符串“user_id”不等于整数“8”。

#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".

单引号用于字符串常量。因此,字符串“user_id”不等于整数“8”。