我在使用INNER JOIN时遇到了麻烦。我假设我在理论上做了一些批判但基本的错误。
表格结构:
我创建了一个页面,其中列出了当前使用BookDB表的签出状态签出的所有书籍。但当然这并不能让我知道是谁拥有它。
为了还显示已经签出书籍的人,我想调用LibraryDB,记录谁检查了它,然后调用StudentDB,其中包含学生的姓名等。
所以我这样做了一个查询:
SELECT * FROM BookDB
INNER JOIN LibraryDB ON BookDB.barcode = LibraryDB.barcode
INNER JOIN StudentDB ON LibraryDB.studentid = StudentDB.studentid
WHERE BookDB.status = '$checkinstatus'
ORDER BY title ASC
问题在于,不是仅仅获得最近检查过的人的结果,而是让每个人都检查过它。
我意识到这可能很简单,但我已经尝试过查看其他类似的帖子,似乎无法弄清楚这里的基本问题。我意识到我需要以某种方式限制查询,但不知道按照我想要的方式执行它的语法。
提前致谢。
编辑:我当前的输出如下:
Animals in danger A1 Shingen Tomita 9780194233798 Edit Book Delete Book
Armans journey A1 Ayaka Morikawa 9780521184939 Edit Book Delete Book
Armans journey A1 Ayaka Morikawa 9780521184939 Edit Book Delete Book
Armans journey A1 Naomi Maki 9780521184939 Edit Book Delete Book
Armans journey A1 Naomi Maki 9780521184939 Edit Book Delete Book
Armans journey A1 Iwamoto Kazumi 9780521184939 Edit Book Delete Book
Armans journey A1 Iwamoto Kazumi 9780521184939 Edit Book Delete Book
Armans journey A1 Kanata Shokai 9780521184939 Edit Book Delete Book
Bens big swim OD1 Keiichiro Takemura 9780194722674 Edit Book Delete Book
Bens big swim OD1 Keiichiro Takemura 9780194722674 Edit Book Delete Book
Bens big swim OD1 Takato Suzuki 9780194722674 Edit Book Delete Book
对于所有相同的书籍,我想输出每本独特书籍的最后一个条目:
Animals in danger A1 Shingen Tomita 9780194233798 Edit Book Delete Book
Armans journey A1 Kanata Shokai 9780521184939 Edit Book Delete Book
Bens big swim OD1 Takato Suzuki 9780194722674 Edit Book Delete Book
答案 0 :(得分:0)
你可以这样试试:
SELECT * FROM BookDB,LibraryDB,StudentDB WHERE BookDB.barcode = LibraryDB.barcode AND LibraryDB.studentid = StudentDB.studentid AND BookDB.status = '$checkinstatus' ORDER BY title ASC;
答案 1 :(得分:0)
所以我无法弄清楚要做什么,所以我只是去了BookDB中添加一个列,显示最近的check-outer是谁,这消除了调用LibraryDB记录表的需要,因此要小心得到每一个过去记录的问题,而不仅仅是最近的记录。