MySQL错误:#1242 - 子查询返回超过1行

时间:2016-03-26 04:47:00

标签: mysql mysql-error-1242

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中的外键。 我想将书籍信息表中的标题字段添加到交易信息表

2 个答案:

答案 0 :(得分:0)

由于contains(_:)外键,它引用了Transaction_Information.BookId表中的相应行,因此一个简单的Book_Information就可以完成这项工作。

以下是查询:

INNER JOIN

答案 1 :(得分:0)

尝试此查询:

select * from Transaction_Information tf,Book_Information bf where tf.BookId = bf.BookID and tf.DueDate <= CURDATE() and tf.ReturneDate is null ;
相关问题