MySQL 查询:从两个表中检索信息,而无需执行两次查询
我的数据库中有两个表,我想从它们中检索信息而不必执行两次查询。基本上,需要使用从任务表检索的 user_ID 从用户表中获取相应的用户名。这是我到目前为止所拥有的,但查询返回 false:
SELECT t.user_id, t.nursery_ss, t.nursery_ws, t.greeter, t.date
u.user_first_name, u.user_last_name
FROM tasks_tbl AS t
INNER JOIN users_tbl AS u ON t.user_id = u.user_id
WHERE t.date = '2009-11-29'
I have two tables in my database, and I would like to retrieve information from both of them without having to do two queries. Basically, the user_ID(s) retrieved from the tasks table needs to be used to get those respective user(s) names from the users table. This is what I have so far, but the query is returning false:
SELECT t.user_id, t.nursery_ss, t.nursery_ws, t.greeter, t.date
u.user_first_name, u.user_last_name
FROM tasks_tbl AS t
INNER JOIN users_tbl AS u ON t.user_id = u.user_id
WHERE t.date = '2009-11-29'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您忘记了选择列表中
t.date
之后的逗号:You forgot a comma after
t.date
in your select-list:事实上,你的查询看起来不错;您可以尝试检查查询的其他方面是否有错误。例如,尝试仅从指定的联接中执行 SELECT *。或者尝试省略 WHERE 子句;您将获得比您想要的更多的数据,但它可以帮助您调试查询。
Actually, your query looks good; you might try checking to see if other aspects of the query are faulty. For example, try just a SELECT * from your join as specified. Or try omitting your WHERE clause; you'll get more data than you want, but it may help you debug your query.