I'm trying to select information from multiple tables within my database which display the details of multiple books and orders.
I am querying the isbn into 5 tables (author, bookauthor, book, orderline, and bookorder) of a certain book to retrieve information about the book and information for orders that have been placed for that book.
SELECT orderline.isbn, title, ordernumber, orderdate, customername, numcopies, orderline.bookprice, authorname
FROM author natural join bookauthor natural join book join orderline natural join bookorder
WHERE orderline.isbn = book.isbn
and book.isbn = "1491936169"
ISBN: 1491936169 Title: Kafka: The Definitive Guide: Real-Time Data and Stream Processing at Scale
Author: Neha Narkhede, Todd Palino, Gwen Shapira
Order Number Date Customer Copies Price Total
N201699998 2016-12-24 Mary Hall 2 33.99 67.98
N201799999 2017-01-03 Aran Clauson 1 33.99 33.99
Total:
However there are some isbns which have not been ordered and have thus are not present in the orderline table but are in the book table, which displays an isbn for all books.
I want to display the book information for those books which do not have orders as well such as:
ISBN: 0387848576 Title: The Elements of Statistical Learning
Author: Jerome Friedman, Trevor Hastie, Robert Tibshirani
No orders
essentially I want a table displaying the book information for the isbn and null values where there are no orders. I imagine this would be some sort of natural outer join, however my attempts have resulted in empty tables.
Updated query attempting to remove duplicates using group by
SELECT ordernumber, orderdate, customername, orderline.isbn, title, orderline.numcopies, stock, shipmentbook.numcopies as shipcopies, authorname
FROM author natural join bookauthor natural join book left join bookorder natural join orderline
ON book.isbn = orderline.isbn
left join mousavs.shipmentbook
ON book.isbn = shipmentbook.isbn
WHERE stock > orderline.numcopies
GROUP BY ordernumber
ORDER BY orderdate, ordernumber, ISBN
Error Code: 1055. Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mousavs.orderline.isbn' which is not functionally dependent on columns in GROUP BY clause