简体   繁体   中英

MySQL query not returning the desired results

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.

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

AND gender = 0在您的查询中,而表格的两个人都设置为1

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM