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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:01:39+00:00 2026-06-18T07:01:39+00:00

I have data in 1 table as UserID CourseID TestID Result 1 1 1

  • 0

I have data in 1 table as

UserID CourseID TestID   Result
1         1       1        P
1         1       2        P
2         1       1        F
2         1       2        F

this is showing that 2 Users ( UserID =1 and 2) has taken Test ( TestID=1 and 2) in CourseID =1

Now that CourseID in total has 3 Tests ( say TestID=1,2,7) as

CourseID TestID
1          1
1          2
1          7

this means none of the user has taken Test ( TestID=7) show now i want to show data as below

UserID CourseID TestID   Result
1         1       1        P
1         1       2        P
1         1       7        null
2         1       1        F
2         1       2        F
2         1       7        null

I have been trying with left/right outer join with Group by, but could not get the desired result. How it can be achieved?

  • 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-06-18T07:01:40+00:00Added an answer on June 18, 2026 at 7:01 am

    SQL Fiddle

    MS SQL Server 2008 Schema Setup:

    create table Result
    (
      UserID int,
      CourseID int,
      TestID int,
      Result char(1)
    )
    insert into Result values
    (1,         1,       1,        'P'),
    (1,         1,       2,        'P'),
    (2,         1,       1,        'F'),
    (2,         1,       2,        'F')
    
    create table Course
    (
      CourseID int,
      TestID int
    )
    
    insert into Course values
    (1, 1),
    (1, 2),
    (1, 7)
    

    Query 1:

    select U.UserID,
           C.CourseID,
           C.TestID,
           R.Result
    from (
         select distinct UserID
         from Result
         ) as U
      cross apply Course as  C
      left outer join Result as R
        on R.CourseID = C.CourseID and
           R.TestID = C.TestID and
           R.UserID = U.UserID
    

    Results:

    | USERID | COURSEID | TESTID | RESULT |
    ---------------------------------------
    |      1 |        1 |      1 |      P |
    |      1 |        1 |      2 |      P |
    |      1 |        1 |      7 | (null) |
    |      2 |        1 |      1 |      F |
    |      2 |        1 |      2 |      F |
    |      2 |        1 |      7 | (null) |
    

    Note: If you have a table Users you could replace the derived table

     (
     select distinct UserID
     from Result
     ) as U
    

    with Users as U instead.

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

Sidebar

Related Questions

Right now I have a table that may or may not have data for
I have a table customers where each cust has UserID as A000 now I
I have set up 2 two tables - table userid and table data in
I have two tables set up in phpmyadmin- table userid and table data. The
I have a data.table object like this one library(data.table) a <- structure(list(PERMNO = c(10006L,
I have the data table from the jquery plugin dataTables (http://datatables.net/) that I want
I have a simpe table: Users UserID Guid doesnt allow null Avatar image allows
I have a table with many rows of data, which has an column filled
I have some data pollution in a table that I'm having a hard time
I have GetConversationPaged sp that selects paged data from table called user_messages_index and includes

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.