MYSQL:查询仅适用于一个值?
我有一个 mysql 查询,如下所示:
$query = "SELECT * FROM users
JOIN signup ON users.uid = signup.uid
JOIN jobs ON users.category_id = jobs.id
JOIN lclasses ON users.class = lclasses.class_id
JOIN degrees ON users.degree_id = degrees.degree_id
JOIN trades ON users.trade_id = trades.trade_id
JOIN tradestatuses ON users.trade_status = tradestatuses.status_id
WHERE users.uid='{$id}' LIMIT 1";
如果 $id = 8,则我的查询正确返回。如果我尝试数据库中的任何其他 ID,我会得到一个空结果集。
我在 phpMyAdmin 中测试了查询并得到了相同的结果。当我使用不同的数字时,查询中没有错误,只是一个空结果集,但我可以在“浏览”部分中查看该行。我的表损坏了吗?有人遇到过类似的事情吗?
I have a mysql query that looks like this:
$query = "SELECT * FROM users
JOIN signup ON users.uid = signup.uid
JOIN jobs ON users.category_id = jobs.id
JOIN lclasses ON users.class = lclasses.class_id
JOIN degrees ON users.degree_id = degrees.degree_id
JOIN trades ON users.trade_id = trades.trade_id
JOIN tradestatuses ON users.trade_status = tradestatuses.status_id
WHERE users.uid='{$id}' LIMIT 1";
If $id = 8, then my query returns properly. If I try any other id that's in my database, I get an empty result set.
I tested the query in phpMyAdmin and get the same result. No errors in the query when I use the different numbers, just an empty result set yet I can look at the row right in the Browse section. Is my table corrupted? Anybody had anything like that ever happen to them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
空结果集就是空结果集。
由于它们都是内部联接,任何一个联接都可能“链接到任何内容”(从而产生空结果集)。如果不仔细检查数据,就无法多说。我会考虑将查询分解为几个部分,看看哪一部分“不起作用”。
快乐编码。
mu 的帖子评论中的有用建议:
An empty result set is an empty result set.
Since they are all INNER JOINS, any one of the joins could be "linking to nothing" (and thus resulting an empty result set). It is impossible to say more without careful inspection of the data. I would consider breaking the query down into parts to see which part "doesn't work".
Happy coding.
Helpful advice from mu's post comment:
问题可能出在查询逻辑中。要检查它,请提供表格说明以及预期结果。查找错误的一个实用方法是注释其他连接。
从开始
然后添加查找连接来切割记录
Probably, problem is in a query logic. To check it, please supply description of tables and what are expected results. A good practical way to find an error is commenting of other joins.
Start from
And then add find join which cut the records