Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL where clause on inner joins

I am working with pgadminIII (postgreSQL)

I have the following tables: Book, Publisher, OrderLine, ShopOrder.

With the following SQL:

SELECT 
    Book.BookID AS "Book ID"
    ,Book.Title AS "Book title"
    ,SUM(OrderLine.quantity) AS "Number Ordered"
    ,ShopOrder.OrderDate AS "Order Date"
FROM (((Book

INNER JOIN OrderLine
ON Book.BookID = OrderLine.BookID)

INNER JOIN Publisher
ON Book.PublisherID = Publisher.PublisherID )


INNER JOIN ShopOrder
ON OrderLine.ShopOrderID = ShopOrder.ShopOrderID)

GROUP BY ShopOrder.OrderDate, Name, Book.BookID

.

I would like to use this with a (WHERE Publisher.Name = "Smith Smitheson")

I dont know where to put it, or if im doing it right, any help please?

like image 529
Edward Savage Avatar asked Apr 23 '16 19:04

Edward Savage


1 Answers

...
INNER JOIN Publisher ON Book.PublisherID = Publisher.PublisherID AND Publisher.Name = 'Smith Smitheson' )
...

or

SELECT Book.BookID AS "Book ID" ,Book.Title AS "Book title"   
,SUM(OrderLine.quantity) AS "Number Ordered" ,ShopOrder.OrderDate AS  
"Order Date" FROM Book
INNER JOIN OrderLine ON Book.BookID = OrderLine.BookID
INNER JOIN Publisher ON Book.PublisherID = Publisher.PublisherID 
INNER JOIN ShopOrder ON OrderLine.ShopOrderID = ShopOrder.ShopOrderID
WHERE Publisher.Name = 'Smith Smitheson'
GROUP BY ShopOrder.OrderDate, Name, Book.BookID
like image 88
George Poliovei Avatar answered Sep 19 '22 05:09

George Poliovei