I have a homework question please help with a little explanation so that I can understand.
You are writing a query, looking for all customers who have never ordered a pepperoni pizza. Which of these queries is the best match?
select distinct
c.customer_name
from
customer c,
orders o
where
o.customer_id = c.customer_id
and o.pizza_type = ‘pepperoni
select
c.customer_name
from
customer c
where
c.customer_id not in
(
select
o.customer_id
from
orders o
where
o.pizza_type != ‘pepperoni’
)
select distinct
c.customer_name
from
customer c
left join orders o
on on.customer_id = c.customer_id
and o.pizza_type = ‘pepperoni’
where
o.pizza_type is null
select
c.customer_name
from
customer c,
orders o
where
o.customer_id = c.customer_id
and o.pizza_type = ‘pepperoni’
group by
c.customer_name
having count(*) = 0
3, assuming that
on.customer_idis a typo on your part that should beo.customer_idExplanation:
1: Selects all customers who have ordered a pepperoni pizza.
2: Selects all customers who have only ever ordered a pepperoni pizza.
3: Selects all customers who have never ordered a pepperoni pizza.
4: Won’t select anyone.