I am having a problem with a SQL query:
select
o.orderID,c.city
from
`order` o, `customer` c, `ordered_items` oi
where
o.FKCustomerID = c.customerID
and o.orderStatus = 'IN PROGRESS'
and o.orderID = oi.FKOrderID
and (select FKDepartmentID
from ordered_items
where orderedItemsID in (select orderedItemsID
from ordered_items
where FKOrderID = o.orderID)
and FKDepartmentID = 11)
order by
c.city asc
It gives me an error saying, nested query returns more then one row.
What I want to using that nested query is this,
In the table order id: 819-DBD-EB8-0E7 has 3 items. I want to get that order no only if all the ordered items are in department ID 11. (FKDepartmentID=11)
So there is 3 items for that order and all items are in department 11. So that order should be retrieved. If there is only 2 items in that department it should not be retrieved.
How to get that using sql query? In my query other part except inner query is ok.
Need to correct the inner query.
Thanks.