I have the query below which queries the following two tables:
我在下面的查询查询以下两个表:
Users
id | gender | interested_men | interested_wmen | name | dob | email | account | photoURL | timestamp
8 | 1 |0 |1 |Jamie |1987-07-04|jampez77@gmail.com| 1 | https://.|2015-11-16 17:47:33
9 | 0 |1 |1 |Jamima|1987-07-04|jampez87@gmail.com| 1 | https://.| 2015-11-17 14:51:38
Locations
id | uid | lat | lng | timestamp
8 | 9 | 53.47213437 | -2.06999151 | 2015-11-17 15:05:37
7 | 8 | 53.47213437 | -2.06999151 | 2015-11-16 17:47:33
Here is the query, I'd expect it to return the details for the user called Jamima but I don't get any results. I can't see anything wrong with the syntax so i'm not sure.
这是查询,我希望它返回名为Jamima的用户的详细信息,但我没有得到任何结果。我看不出语法有什么问题,所以我不确定。
SELECT DISTINCT
l.uid ,
u.account ,
(
3959 * acos
(
cos(
radians(53.47213437)
) *
cos(
radians( lat)
) *
cos(
radians( lng) - radians(-2.06999151)
) +
sin(
radians(53.47213437)
) *
sin(
radians( lat )
)
)
) distance,
TIMESTAMPDIFF(YEAR, dob, CURDATE()) AS age
FROM locations l
INNER JOIN users u ON l.uid = u.id
WHERE uid != 8
AND gender = 0
AND account = 1
HAVING distance <= 200
AND age >= 23
AND age <= 33
ORDER BY RAND()
I've noticed that if I remove the gender and account parts of the where clause i get the correct results through. even if though they match the where clause
我注意到,如果我删除where子句的性别和帐户部分,我会得到正确的结果。即使它们匹配where子句
2 个解决方案
#1
0
AND gender = 0
is in your query while the table has the value of 1 set for both people
AND性别= 0在您的查询中,而表格为两个人设置了值1
#2
0
This was an issue with the datatypes in MySQL. For some reason the fact I had gender and account set to ENUM created the issue. I simply changed the to INT and everything was fine.
这是MySQL中数据类型的问题。出于某种原因,我将性别和帐户设置为ENUM这一事实造成了问题。我只是改为INT,一切都很好。
#1
0
AND gender = 0
is in your query while the table has the value of 1 set for both people
AND性别= 0在您的查询中,而表格为两个人设置了值1
#2
0
This was an issue with the datatypes in MySQL. For some reason the fact I had gender and account set to ENUM created the issue. I simply changed the to INT and everything was fine.
这是MySQL中数据类型的问题。出于某种原因,我将性别和帐户设置为ENUM这一事实造成了问题。我只是改为INT,一切都很好。