在SQL数据库中连接两个表 [英] Join two tables in SQL database
本文介绍了在SQL数据库中连接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在SQL数据库中创建了两个表'Student'和'Book'。 '学生'表包括'卷号(主键),名称'列和'书'表包含'书号(主键),书名,作者姓名'。我如何加入这两张桌子,以便知道哪些书籍发给哪个学生。实际上我会将学生卷号输入我的课程,然后检查发给该学生的书籍。
需要帮助..
谢谢..
I have two tables 'Student' and 'Book' created in a SQL databse. 'Student' table consists of 'Roll number(Primary Key), Name' columns and 'Book' table consists of 'Book number(Primary key), Book name, Author name'. How can I join the two tables such that I know which books are issued to which Student.. Actually I will make Student Roll number feed into my program and then check the books issued to that student..
Help required..
Thank You..
推荐答案
简单的答案是:
你需要一张第三张表StudentHasBorrowedBook有2个PKs colums卷号和书号。
如果你有2个打印件,这个问题可能会变得复杂得多相同的'Book'
The simple answer is :
you need a 3rd table StudentHasBorrowedBook with 2 PKs colums Roll number and Book number.
That said the question might become much more complicated if you have 2 prints of the same 'Book'
SELECT Student.Rollnumber,Book.Bookname,Student.Studentname
FROM Student
INNER JOIN Book
ON Student.Booknumber = Book.Booknumber;
SELECT Student.Rollnumber, Book.Bookname, Student.Studentname
FROM Student
INNER JOIN Book
ON Student.Booknumber=Book.Booknumber;
这篇关于在SQL数据库中连接两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文