英文:
How to use Inner Join along with Where in MySQL?
问题
在学费表中,我有两个字段分别是user_id
和admin_id
。我使用Inner Join
子句和user_id
访问相关的用户:
SELECT * FROM tuition t JOIN user u ON t.user_id = u.id
但在学费表中,我只想连接那些admin_id
等于1
的记录。我应该如何重新编写上面的子句?我尝试过以下方式但没有显示任何结果:
SELECT * FROM tuition t JOIN user u ON t.user_id = u.id WHERE admin_id=1
SELECT * FROM tuition t WHERE admin_id=1 AND JOIN user u ON t.user_id = u.id
英文:
I have 2 separate tables which are tuition and user. In the tuition table I have 2 fields named user_id
and admin_id
. I access related users by using Inner Join
clause and user_id
:
SELECT * FROM tuition t JOIN user u ON t.user_id = u.id
But in the tuition table, I want join only records in tuition which their admin_id
is equal to 1
. How should I rewrite the clause above? I wrote as this but didn't show me anything:
SELECT * FROM tuition t JOIN user u ON t.user_id = u.id WHERE admin_id=1
SELECT * FROM tuition t WHERE admin_id=1 AND JOIN user u ON t.user_id = u.id
答案1
得分: 1
Where clause with inner join queries should be referenced with table name.
SELECT * FROM tuition t JOIN user u ON t.user_id = u.id WHERE t.admin_id=1
英文:
Where clause with inner join queries should be referenced with table name.
SELECT * FROM tuition t JOIN user u ON t.user_id = u.id WHERE table_name.admin_id=1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论