Let’s say we have three tables in a relational database:
Person {id, name}
Obstacle {id, name}
Person_overcomes_obstacle {person_id, obstacle_id}
I want to write a query that tells me if at least one person has overcome all obstacles. Ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I notice that I was the only person to use the natural table alias for
Person_overcomes_obstacle!You need a relational division query for this.
You can either count up the obstacles and the matching records in Person_overcomes_obstacle and return ones where the 2 numbers match or look at it another way as finding people for which there is no obstacle that they haven’t overcome.