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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:44:45+00:00 2026-06-13T10:44:45+00:00

I usually go with the join approach but in this case I am a

  • 0

I usually go with the join approach but in this case I am a bit confused. I am not even sure that it is possible at all. I wonder if the following query can be converted to a left join query instead of the multiple select in used:

select 
   users.id, users.first_name, users.last_name, users.description, users.email 
from users 
where id in (
     select assigned.id_user from assigned where id_project in (
            select assigned.id_project from assigned where id_user = 1
                                                               )
            ) 
   or id in (
     select projects.id_user from projects where projects.id in (
            select assigned.id_project from assigned where id_user = 1
                                                                )
            )  

This query returns the correct result set. However, I guess the repetition of the query that selects assigned.id_project is a waste.

  • 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-13T10:44:47+00:00Added an answer on June 13, 2026 at 10:44 am

    Since both subqueries have a condition where assigned.id_user = 1, I start with that query. Let’s call that assignment(s) the ‘leading assignment’.

    Then join the rest, using left joins for the ‘optional’ tables.
    Use an inner join on user that matches either users of assignments linked to the leading assignment or users of projects linked to the leading project.

    I use distinct, because I assumen you’d want each user once, event if they have an assignment and a project (or multiple projects).

    select distinct
      u.id, u.first_name, u.last_name, u.description, u.email 
    from 
      assigned a
      left join assigned ap on ap.id_project = a.id_project
      left join projects p on p.id = a.id_project
      inner join users u on u.id = ap.id_user or u.id = p.id_user
    where
      a.id_user = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why is string concatenation faster than array join? Usually we need to
I have two entities that usually have one-to-many relationship, but in rare cases should
I'm usually pretty well versed with JOINS, but this is new. Suppose three tables
I know this error is usually a problem with unclosed quotes and such, but
kdb+ has an aj function that is usually used to join tables along time
I'm having a bit of problem understanding outer join, I think. This is a
Take a typical left outer join scenario. We all know that the order of
I've read that table joins are usually more efficient over sub queries, is this
I'm not sure exactly how to get this. What I have is something like
Is that possible to define a function without referencing to self this way? def

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.