Chasing my tail trying to figure this out, googling it just leads to far more complicated examples.
I've joined two tables, which join fine. Prof has asked us to list rows from the orders table where shipped date is NULL, or in the words of the exercise, 'orders that have not shipped yet.'
Join works fine until I add the IS NULL line and then I get the error: Msg 156, Level 15, State 1, Line 13 Incorrect syntax near the keyword 'LEFT'.
I've written this 20 different ways and spent the afternoon googling it but can't get rid of the error. I know it's going to be something simple but...
SELECT
customers.customer_id,
customers.name,
customers.phone,
orders.order_id,
orders.order_date,
orders.shipped_date
FROM
orders
WHERE
orders.shipped_date IS NULL
LEFT OUTER JOIN customers ON customers.customer_id=orders.customer_id
There is a defined order of how to compose a query
select
from
join
where
group by
having
order by
You cannot mix that order.
LEFT JOIN
should come first before the WHERE
clause.
SELECT customers.customer_id,
customers.name,
customers.phone,
orders.order_id,
orders.order_date,
orders.shipped_date
FROM orders
LEFT OUTER JOIN customers
ON customers.customer_id=orders.customer_id
WHERE orders.shipped_date IS NULL
For additional information about joins, see
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With