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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:29:34+00:00 2026-05-28T03:29:34+00:00

Okay, so these are my three tables: USER |——–+———-+———-| | UserID | UserName |

  • 0

Okay, so these are my three tables:

USER

|--------+----------+----------|
| UserID | UserName | IsActive |
|--------+----------+----------|
|   10   |   Mike   |     1    |
|   11   |   John   |     1    |
|   12   |   Beth   |     1    |
|--------+----------+----------|

REPORT_DISTRIB (Linking Table)

|-----------+--------+----------+---------------|
| DistribID | UserID | ReportID | DistribToUser |
|-----------+--------+----------+---------------|
|     1     |   10   |    50    |       1       |
|     2     |   12   |    52    |       0       |
|     3     |   14   |    54    |       1       |
|-----------+--------+----------+---------------|

REPORT

|----------+------------+---------------|
| ReportID | ReportName | Distributable |
|----------+------------+---------------|
|    50    |   FY2010   |       1       |
|    51    |   FY2011   |       1       |
|    52    |   FY2012   |       1       |
|----------+------------+---------------|

In the problem I’m facing, I have 200 users from the USER table that are active and 10 reports from the REPORT table that are distributable. For every user I need to display the User Name, the Report Name, and whether that report should be distributed to the user, like so:

|----------+------------+---------------|
| UserName | ReportName | DistribToUser |
|----------+------------+---------------|
|   Mike   |   FY2010   |       1       |
|   Beth   |   FY2012   |       0       |
|----------+------------+---------------|

What I’m trying to achieve is a list of 2000 results (200 users x 10 reports). The problem is that the REPORT_DISTRIB linking table doesn’t have a record for every user with each report. I still feel like this should be possible… am I wrong in my thinking? Any help is greatly appreciated.

It’s rough, but this is my query so far (which returns 1790 results):

SELECT u.UserName, r.ReportName, rd.DistribToUser
FROM USER u
LEFT JOIN REPORT_DISTRIB rd on rd.UserID = u.UserID
  and rd.ReportID in (select r.ReportID from REPORT r where r.Distributable = 1)
OUTER APPLY (select r.ReportName from REPORT r where r.ReportID = rd.ReportID) r
WHERE u.IsActive = 1
  • 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-28T03:29:35+00:00Added an answer on May 28, 2026 at 3:29 am
    SELECT u.UserName, r.ReportName, COALESCE(rd.DistribToUser, 0)
        FROM USER u
            CROSS JOIN REPORT r
            LEFT JOIN REPORT_DISTRIB rd
                ON u.UserID = rd.UserID
                    AND r.ReportID = rd.ReportID
        WHERE u.IsActive = 1
            AND r.Distributable = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, these two related questions are in reference to Railscast #21 : I'm having
Okay basically here's where I'm at. I have a list of PropertyDescriptor objects. These
So I have three tables I am trying to pull data from with the
Okay, so I'm making a plugin to allow inline editing of tables in my
Okay, There seems to be a lot of discussion on here about how terribly
Well, okay. There's Visual Studio 2008 and Embarcadero Delphi/Studio that are both able to
Okay, I have ran in to a problem with VB.NET. So all those defenders
Okay, I've looked all over the internet for a good solution to get PHP
Okay, so I'm running a small test webserver on my private network. I've got
Okay so im working on this php image upload system but for some reason

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.