SELECT BookId, Duedate, (SELECT Title FROM Book_Information WHERE BookId = BookId)
FROM Transaction_Information WHERE DueDate <= CURDATE() AND ReturnedDate IS NULL
book id 是 transaction_information 中的外键。我想将书籍信息表中的 Title 字段添加到交易信息表中
SELECT BookId, Duedate, (SELECT Title FROM Book_Information WHERE BookId = BookId)
FROM Transaction_Information WHERE DueDate <= CURDATE() AND ReturnedDate IS NULL
book id 是 transaction_information 中的外键。我想将书籍信息表中的 Title 字段添加到交易信息表中
由于Transaction_Information.BookId
是引用表中相应行的外键Book_Information
,那么一个简单的INNER JOIN
就可以完成这项工作。
这是查询:
SELECT
TF.BookId,
TF.Duedate,
BF.Title
FROM Transaction_Information TF
INNER JOIN Book_Information BF
ON TF.BookId = BF.BookId
WHERE TF.DueDate <= CURDATE() AND TF.ReturnedDate IS NULL;
试试这个查询:
select * from Transaction_Information tf,Book_Information bf where tf.BookId = bf.BookID and tf.DueDate <= CURDATE() and tf.ReturneDate is null ;