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

  • SEARCH
  • Home
  • 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 6235639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:42:17+00:00 2026-05-24T10:42:17+00:00

I have a products table with a stock field and a timestamp field that

  • 0

I have a products table with a stock field and a timestamp field that indicates the last time the product has been updated.

I need to write a query that pulls all the products that have stock>=0 and, for those that stock=0, to check if the difference between the timestamp and the current time is less than 30 days . If stock=0 and datediff(now(), timestamp)>30 then to exclude the products from the recordset.

So far I’ve written a query (see below) but it’s incorrect as it will exclude even the products with stock>0 when they havent been updated in a the past 30 days.

select * from products where stock>=0 and datediff(now(), timestamp)>=30;
  • 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-24T10:42:19+00:00Added an answer on May 24, 2026 at 10:42 am

    Is it what you want?

    SELECT * FROM products WHERE stock > 0 OR stock = 0 AND DATEDIFF(NOW(), timestamp) <= 30;
    

    If stock field is unsigned, the condition ‘stock = 0’ can be removed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have a products table that contains normal products and configurable product It
I have table 'products' and I need to update 'price' field by 20% if
So I have a table of products. Each product has a price (decimal) and
I have a query that successfully grabs the unique products from my products table
I have a table with products. artID artName stock order 1 cables *100 0
Ok...so I have a page that lists products from a table based on the
I have 3 tables products and stock and purchases . Puchases has a primary
I have a table with products, their amount and their price. I need to
I have a report that is supposed to show the Stock Value of products
I have a table orderDetails that contains the products of an order productId color

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.