2
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 字段添加到交易信息表中

4

2 回答 2

0

由于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;
于 2016-03-26T06:23:49.543 回答
0

试试这个查询:

select * from Transaction_Information tf,Book_Information bf where tf.BookId = bf.BookID and tf.DueDate <= CURDATE() and tf.ReturneDate is null ;
于 2020-06-15T07:01:17.137 回答