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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:15:46+00:00 2026-06-09T02:15:46+00:00

I’ve been having trouble finding a way to retrieve data – I need a

  • 0

I’ve been having trouble finding a way to retrieve data – I need a way to traverse multiple foreign key relationships in a mysql query. The general table structure is as follows:

Subjects (table)
-id
-fname
-lname
-etc.

Events(table):
-id
-subject_id
-procedure_id
-date

Procedures(table):
-id
-description

These identifiers are used in other tables, such as:

Assessment1(table):
-id
-event_id
-data, etc.

Assessment2(table):
-id
-event_id
-data, etc.

The problem I’m having is in being able to pull all of the assessment data for subjects that have events for both Assessment 1 and Assessment 2. I’ve been able to successfully pull data for one assessment, or for two assessments that share the same event_id, in this example, Assessment1 and Assessment 1a. But I need a way to be able to link based on the subject_id, which is not in the assessment table as this goes through the Events table.

The query that I have used successfully (based off of event_id) is:

select 
    s.first_name, 
    s.last_name, 
    s.ssn, 
    e.subject_id, 
    n.*,
    l.Q23 
from 
    subjects s, 
    events e, 
    Assessment1 n, 
    Assessment1a l 
where 
    e.subject_id = s.id 
    and l.event_id = e.id 
    and l.Q23 = "1" 
    and n.event_id = e.id

How can I modify this to pull data for assessments with different event_ids but the same subject_ids?

  • 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-09T02:15:48+00:00Added an answer on June 9, 2026 at 2:15 am

    How can I modify this to pull data for assessments with different event_ids but the same subject_ids?

    I think this is what you need.

    SELECT *
    FROM subjects s
    JOIN events e1 ON e1.subject_id = s.id
    JOIN events e2 ON e2.subject_id = s.id and e1.id != e2.id
    JOIN assessment1 a1 ON a1.event_id = e1.id
    JOIN assessment2 a2 ON a2.event_id = e2.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

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.