Mysql – Remove result set doesnt meet criteria

MySQL

This is part of a query result :
enter image description here

I'm going to add a constraint to my query to remove the orders that don't have an invoice_type = final, so the first three rows should be removed and the last three rows should remain in the result.

How should I do that?

Best Answer

I think this query will work for you :

select 
  order_item_id,
  order_id,
  invoice_id,
  invoice_type
from your_table
where order_item_id in 
(select order_item_id from your_table where invoice_type = 'final' group by order_item_id)