Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:27:21+00:00 2026-05-24T12:27:21+00:00

I was hoping I could get some help with a Query I am trying

  • 0

I was hoping I could get some help with a Query I am trying to figure out. Our online store needs to know when all variants of a product are at quantity zero so we can disable the product from customer view. The table I am working with is just the variant table.

we’ll call it cart_variants

| variantid | productid | avail |
| 5677      |   1310    |   0   |
| 5399      |   1310    |   2   |
| 5228      |   1223    |   0   |
| 5133      |   1223    |   0   |

I need to return all productids who’s variant quantities are all zero. Product ids can have any amount of variants. In the example above the query would only return productid 1223.

I’m pretty sure this is not a really complex query but it sure has kicked me butt.
As close as I’ve been able to come was:

SELECT productid, SUM(avail)as qty FROM 'cart_variants' GROUP BY productid

That gives me the list of all products and their qtys but I cant figure out how to get it into a temp table and query the productid with qty = 0.

Most of the examples working with temp tables and select queries are not very clear. I tried several incarnations and none of them worked to completion.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:27:22+00:00Added an answer on May 24, 2026 at 12:27 pm

    Assuming that you’d never have a negative avail value, you really only need to apply a HAVING clause to your query:

    SELECT c.productid
        FROM cart_variants c
        GROUP BY c.productid
        HAVING SUM(c.avail) = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was hoping someone could help a noobie out. I am trying to create
I was hoping I could get some help optimizing the following data retrieval. Here
I'm not seeing the error and was hoping someone could figure it out: public
hoping to get some help here. I have locations on a database that I
I'm hoping to get some help with this weird problem. We're running the Jacorb
I have been playing with generics and was hoping I could get some feedback
I am hoping to get some help solving a problem that I'm sure many
I have a small problem that I am hoping to get some help with.
Im using the .NET framework 1.1 and Im hoping someone could help me implement
I have a problem, and was hoping I could rely on some of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.