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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:03:26+00:00 2026-06-02T03:03:26+00:00

I have 2 tables structured like this: People ———- >ID, Name, Surname Projects ———-

  • 0

I have 2 tables structured like this:

People
----------
>ID, Name, Surname

Projects
----------
>ID, Assistant#1,  Assistant#2,  Assistant#3,  Assistant#4, 
> Assistant#5,  Assistant#6,  Assistant#7,  Assistant#8,  Assistant#9, 
> Assistant#10, lot of other columns..... (every assistant column
> contains an integer, the people ID)

Now, I want to query my DB and get a single row from Project table (let’s suppose row with ID=3) containing all columns of project table and in particular have each assistant replaced with it’s correct name and surname.
I’ve managed to do this (with a lot of joins), but with my little sql experience my code looks very bulky and i’m sure that there’s a better way to do this.

Thanks in advance.

  • 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-02T03:03:29+00:00Added an answer on June 2, 2026 at 3:03 am

    Because you set a number of (possible) assistants at 10, that dictates that you are going to have to write code to accomodate those 10 assistants. This can be done a few ways: (have not tested)

    select * from projects proj
    left join people p1 on proj.assistant1 = p1.peopleid
    left join people p2 on proj.assistant2 = p2.peopleid
    left join people p3 on proj.assistant3 = p3.peopleid
    left join people p4 on proj.assistant4 = p4.peopleid
    left join people p5 on proj.assistant5 = p5.peopleid
    left join people p6 on proj.assistant6 = p6.peopleid
    left join people p7 on proj.assistant7 = p7.peopleid
    left join people p8 on proj.assistant8 = p8.peopleid
    left join people p9 on proj.assistant9 = p9.peopleid
    left join people p10 on proj.assistant10 = p10.peopleid
    

    otherwise you could do some trickery with

    select proj.projectID, 
    (select * from people where peopleID = proj.assistant1),
    (select * from people where peopleID = proj.assistant2),
    (select * from people where peopleID = proj.assistant3),
    (select * from people where peopleID = proj.assistant4),
    (select * from people where peopleID = proj.assistant5),
    (select * from people where peopleID = proj.assistant6),
    (select * from people where peopleID = proj.assistant7),
    (select * from people where peopleID = proj.assistant8),
    (select * from people where peopleID = proj.assistant9),
    (select * from people where peopleID = proj.assistant10)
    from projects proj
    

    If possible, it might be best to re-structure your datatables, and have a single assistant mapped to a single projectID:

    PeopleID, Name, Surname
    
    ProjectID, PeopleID
    

    Therefore, you could do just one inner join and you will return a row for each assistant:

    select * from projects proj 
    inner join people p 
    on p.peopleID = proj.peopleid
    where proj.projectID = PROJECTID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table structured somewhat like this: type name value ===================== 1
I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
I have 2 tables like this: [people1]: |First Name*| Last Name*| | | |
I have 2 tables: posts tags Tags table is structured like this: post_id tag
I have a table structured like this: <table> <tr id=id1 class=parent></tr> <tr class=id1></tr> <tr
I'm a bit confused on this. I have a data table structured like this:
I have a couple of tables with similar structures like this: <table> <tbody> <tr>content</tr>
I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
I have a messages table that is structured somewhat like this: from | to
I have a Perl hash of people like this: my $data = { 124535

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.