简体   繁体   English

MySQL join无法从一个表中进行选择

[英]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. 我有一个完全按预期工作的连接,除了从'right'表中选择的任何和所有字段在它们肯定不是时返回空白。

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. 我实际上并不需要整个用户表,只有users.email - 但没有字段可用。 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. 如果用内连接替换左连接返回空结果集,则连接条件/ where子句将被破坏。

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. 如果是这种情况,那么看看你得到的team_id / score.date的值 - 我敢打赌你正在使用表格中根本不存在的绑定值的组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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