troubleshooting Question

MySQL Sub-Query

Avatar of c0mrad
c0mrad asked on
MySQL Server
7 Comments2 Solutions327 ViewsLast Modified:
I am trying to re-write this query without the subquery. It has been a while since I had to rewrite a query and was wondering if anyone may be able to think of a better way to write this:

SELECT `order_groups`.*
FROM `order_groups`  
WHERE `order_groups`.`ship_notified` = 0
AND `order_groups`.`affiliate_id` = 51
AND (
            (
                  select count(*)
                  from orders
                  where order_group_id=order_groups.id
                  and state != 'shipped'
                  and state != 'canceled'
            ) = 0
      AND (
                  select count(*)
                  from orders
                  where order_group_id=order_groups.id
                  and state = 'shipped'
            )
> 0);
ASKER CERTIFIED SOLUTION
Sharath S
Data Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros