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 6611179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:56:13+00:00 2026-05-25T19:56:13+00:00

Hi I have a coupon system that uses one table (called coupons) to store

  • 0

Hi I have a coupon system that uses one table (called “coupons”) to store info about each type of available coupon that one could generate, and another table (generatedcoupons) to store info about each coupon generated. I’m having a hard time comparing info in each table.

The schemas:

table: coupons
+----+------+--------------------+---------------+
|  id| owner|     date_expiration| limit_per_user|
|  15|    34| 2011-09-18 00:00:00|              2|
+----+------+--------------------+---------------+

table: generatedcoupons
+----+----------+------+--------------------+------+--------+
|  id| coupon_id| owner|                date|  used| user_id|
|   1|        15|    34| 2011-09-17 00:00:00| false|     233|
+----+----------+------+--------------------+------+--------+

I’m trying to select all expired coupons for a given user. Is this correct?

select *
from coupons
join generatedcoupons on user_id = 233 and coupon_id=coupons.id
where coupons.owner=34 and (curdate()>date(coupons.date_expiration)
  • 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-25T19:56:13+00:00Added an answer on May 25, 2026 at 7:56 pm

    You need to join on the owner and the coupon id. Then put the values that you want to filter by in the where clause.

    select *
    from coupons c
    join generatedcoupons g on c.owner=g.owner and g.coupon_id=c.id
    where g.user_id = 233 and c.owner=34 and (curdate()>date(c.expiration_date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system that allows users to enter coupons (for example like dell
I have a PHP based website that uses coupon codes. I can restrict search
I have two simple entities: My\Entity\Coupon: type: entity table: coupon id: id: type: integer
I have to add a coupon table to my db. There are 3 types
I have the following 3 classes class User { static hasMany = [coupons: Coupon]
I have three model: raw_coupon coupon store If I'm looping through raw_coupons, how can
I'm writing a django model that allows my site to have coupons. Coupons can
We have this API to our ordering system in our Call-Center, that our online-ordering
I need to select a list of coupons that have not expired yet. That
How does one filter a list of records to remove those that have some

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.