简体   繁体   中英

MySQL join unable to select from one table

I have a join that works exactly as expected, except any and all fields selected from the 'right' table are returned blank when they definitely are not.

SELECT score.recipient, score.amount, u.* FROM score 
LEFT JOIN `users` AS u ON score.recipient = u.id AND u.team_id = ?
WHERE UNIX_TIMESTAMP(score.date) > ?

I don't actually need the entire users table, only users.email - but no fields work. The result set looks like this (sample):

[0] => stdClass Object ( [recipient] => 1 [amount] => 1 [id] => [fname] => [lname] => [nickname] => [email] => [phone] => [reg_key] => )
[1] => stdClass Object ( [recipient] => 103 [amount] => -1 [id] => [fname] => [lname] => [nickname] => [email] => [phone] => [reg_key] => )

All of the fields listed are in fact populated.

Any help would be appreciated! I'm at a loss.

Your join condition / where clause is broken if replacing the left join with an inner join returns an empty result set.

Try this (without bind variables and their conditions) and see if it returns any values:

SELECT score.recipient, score.amount, u.* FROM score 
LEFT JOIN `users` AS u ON score.recipient = u.id 

If that's the case, then look at the values for team_id / score.date you get - I bet you're using a combination of bind values that simply does not exist in your tables.

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