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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:09:32+00:00 2026-05-24T05:09:32+00:00

I have a mysql table with the following columns: id (autoincremented primary key) user_id

  • 0

I have a mysql table with the following columns:

id (autoincremented primary key)
user_id
test_id
test_score

How can I get all test data tied to the users that have participated in test_id = 5. I want all test data (not just test_id 5) for the users that have participated in that particular test.

  • 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-24T05:09:33+00:00Added an answer on May 24, 2026 at 5:09 am

    Sounds like you’d want to do a self-join. Something like this would utilize indexes (assuming you have an index on user_id and an index on test_id, which you should):

    SELECT DISTINCT t1.*
    FROM `tableName` t1
    INNER JOIN `tableName` t2 ON t2.user_id = t1.user_id
    WHERE t2.test_id = 5
    

    I guess that raises another point. How is your table indexed? Just the numeric primary key? You generally want to have indexes on all columns that are used in JOINs or WHERE clauses. Thus, you’d want to have an index on user_id and an index on test_id.

    Can a user take the same test multiple times? If not, then you’d want restrict that by having a unique multiple-column (“composite”) index across user_id and test_id together. And then add a regular index just to test_id for the WHERE clause.

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

Sidebar

Related Questions

I have one MySQL table, users , with the following columns: user_id (PK) email
I have a mysql table with the following columns: group_id game_id user_id message last_update
I have the following MySql table (user_actions) with the following columns: id, user_id, created_at,
I have a MySQL table with the following columns: id(int), date (timestamp), starttime(varchar), endtime(varchar),
I have a (mysql) database table with the following columns: NAME | String (Unique)
Hello I have following columns in mysql table: rating1, rating2, price, cond, approved Is
I have created a mysql table with the following columns... item_price, discount, delivery_charge, grand_total
I have an table in my MySql database that has the following columns: -
I have a mysql table called jos_users_quizzes with the following columns: id quiz_i duser_id
I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment

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.