我有以下数据库架构:
CREATE TABLE "Student" (
"Student_ID" INTEGER PRIMARY KEY NOT NULL ,
"First_Name" CHAR, "Last_Name" CHAR, "Course" CHAR,
"Year" INTEGER, "Semester" INTEGER)
CREATE TABLE "AddBook" ("Book_ID" INTEGER PRIMARY KEY NOT NULL ,
"Name" CHAR, "Edition" INTEGER, "Publisher" CHAR, "Price" INTEGER,
"Page" INTEGER)
我正在制作一张借书书名表问题,我把它放在" Student_ID"和" Book_ID"借用它的日期是数据库模式:
CREATE TABLE "Issue" ("Student_ID" INTEGER PRIMARY KEY NOT NULL ,
"Book_ID" INTEGER NOT NULL ,"Date" INTEGER DEFAULT (null) )
如何显示所有借阅的书籍,但显示所有学生信息以及所有书籍信息和日期
答案 0 :(得分:2)
你可以这样做:
SELECT s.*, b.*, i.date
FROM Issue I
INNER JOIN Student s ON (i.Student_ID = s.Student_ID)
INNER JOIN AddBook b ON (i.Book_ID = b.Book_ID)
INNER JOIN
会使用您提供的ID找到匹配学生和问题表的匹配书。
答案 1 :(得分:0)
你必须同时join这三张桌子:
SELECT *
FROM Issue
JOIN Student USING (Student_ID)
JOIN AddBook USING (Book_ID);