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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:13:59+00:00 2026-06-05T01:13:59+00:00

I have a system where users can complete two types of tests. I need

  • 0

I have a system where users can complete two types of tests. I need to get a list of DISTINCT users sorted by the date of their latest test completion.

For this purpose the tables may as well be set out as:

Test_Users
 - Test_User_Id (int)

Test_1_Results
 - Test_1_Result_Id (int)
 - Test_User_Id (int)
 - Date_Of_Completion (datetime)

Test_2_Results
 - Test_2_Result_Id (int)
 - Test_User_Id (int)
 - Date_Of_Completion (datetime)

I can happily get a list of all the different Test_User_Id‘s using a UNION as follows:

SELECT Test_User_Id FROM Test_1_Results
UNION
SELECT Test_User_Id FROM Test_2_Results

And I could easily sort the results from one of these tables using a ORDER BY Date_Of_Completion DESC but i do not know how to do this with the UNION or if this is even the best way to proceed.

Ultimately i would like to be able to wrap this query within others like:

SELECT *
FROM Test_Users
WHERE Test_User_Id IN (
    //The query i am asking about
)
WHERE some_criteria

But so far i haven’t had any luck doing this while using a UNION and i am not sure what i am doing wrong.

The reason i am trying to do this is that the admin user needs to be able to view a list of everyone who has completed their tests with the most recent completions at the top.

I am fairly familiar with SQL, but i have never really had to use the UNION operator before.

  • 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-05T01:14:00+00:00Added an answer on June 5, 2026 at 1:14 am

    This should work

     SELECT Test_User_Id, max(Date_Of_Completion) AS doc
     FROM ( 
         SELECT Test_User_Id, Date_Of_Completion FROM Test_1_Results
           UNION ALL
         SELECT Test_User_Id , Date_Of_Completion FROM Test_2_Results 
     ) AS temptab
     GROUP BY Test_User_Id
     ORDER BY doc DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system setup where users can post microposts (basically status updates) and
I have a system where registered users can vote up/vote down comments for a
I'm looking content management system that would have features similar to stackoverflow: Users can
I have an system with which users can upload a CSV file via an
We have a system that handles several users where users can spend up to
I have a system whereby a user can view categories that they've subscribed to
I have a user system where user accounts can own subordinate accounts. To express
I have a log in system where a user can check the Remember me
I have make a messaging system in which user can send messages to each
I have a credit system set up on my site where user A can

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.