MrSilent
MrSilent

Reputation: 574

MySQL. Products not sold in a period

I am learning MySQL and I have a question. I have this following assignment and it's pretty new to me, but logically it's easy.

I have the following table:

 id          article_id   quantity     date_sold   price
  1                1            2      2014-05-05    200
  2                2            4      2014-05-12    800
  3                3            5      2014-05-02     35
  4                4            10     2014-05-18     60
  5                5            20     2014-05-23     20
  6                6            2      2014-05-20     26
  7                7            1      2014-05-14     10
  8                8            2      2014-05-12     30
  9                9            6      2014-05-11     12
  10               10           2      2014-05-08      6

And the question sounds like this "Determine the article not sold in a given period. The result would pretty much sound like this: Between 2014-05-10 and 2014-05-20, article 1, 3, 5, 10 have not been sold.

Upvotes: 1

Views: 750

Answers (1)

echo_Me
echo_Me

Reputation: 37253

Try this

  SELECT * from table1
  WHERE id NOT IN ( select id FROM table1 WHERE
             `date_sold` BETWEEN '2014-05-10' and '2014-05-20')

this will give you result of articles which have not been sold between the given dates.

DEMO HERE

Upvotes: 1

Related Questions