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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:25:47+00:00 2026-05-26T18:25:47+00:00

I have 3 tables: ‘CouponType’ table: AutoID Code Name 1 CouT001 SunCoupon 2 CouT002

  • 0

I have 3 tables:

‘CouponType’ table:

 AutoID         Code        Name

    1         CouT001     SunCoupon     
    2         CouT002     GdFriCoupon     
    3         CouT003     1for1Coupon  

‘CouponIssued’ table:

 AutoID              CouponNo        CouponType_AutoID  

    1                 Co001               1 
    2                 Co002               1
    3                 Co003               1                   
    4                 Co004               2
    5                 Co005               2 
    6                 Co006               2    

‘CouponUsed’ table:

  AutoID     Coupon_AutoID

    1              2  
    2              3  
    3              5   

I am trying to join 3 tables together using this query below but apparently I am not getting right values for CouponIssued column:

select CouponType.AutoID, Code, Name, Count(CouponIssued.CouponType_AutoID), count(CouponUsed.Coupon_AutoID)
from (CouponType left join CouponIssued
on (CouponType.AutoID = CouponIssued.CouponType_AutoID))
left join CouponUsed
on  (couponUsed.Coupon_AutoID = CouponIssued.AutoID)
group by CouponType.AutoID, code, name
order by code

The expected result should be like:

**Auto ID         Code           Name             Issued            used**

1                 CouT001       SunCoupon           3                  2

2                 CouT002       GdFriCoupon         3                  1

3                 CouT003       1for1Coupon         0                  0

Thanks!

  • 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-26T18:25:47+00:00Added an answer on May 26, 2026 at 6:25 pm
    SELECT t.AutoID
          ,t.Code
          ,t.Name
          ,count(i.CouponType_AutoID) AS issued
          ,count(u.Coupon_AutoID) AS used
    FROM   CouponType t
    LEFT   JOIN CouponIssued i ON i.CouponType_AutoID = t.AutoID
    LEFT   JOIN CouponUsed u ON u.Coupon_AutoID = i.AutoID
    GROUP  BY 1,2,3;
    

    You might consider using less confusing names for your table columns. I have made very good experiences with using the same name for the same data across tables (as far as sensible).

    In your example, AutoID is used for three different columns, two of which appear a second time in another table under a different name. This would still make sense if Coupon_AutoID was named CouponIssued_AutoID instead.

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

Sidebar

Related Questions

I have tables linked by FK, I query on the first table using entity
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..
In my database I have tables that define types for example Table: Publication Types
hi i have tables like this: Persons: person_id, name then i have many langauge
I have tables: users {id, name} projects {id, name} roles {id, name} projects_users {id,
Hi i have tables like this : table entry : id | total_comments _____________________
I have tables: Teachers and Students. We have a SpecialProjects Table where Teachers and
I have tables like tbl_biodata: id : int value=>1 name : varchar(50) value =>
I have tables item and store (it's a store management system). item table has
I have tables foo and bar: create table foo(a int, b varchar(10), primary key

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.