mirons Posted June 24, 2015 Share Posted June 24, 2015 I have a table of residents who may or may not have records in the contacts table. I want to return ALL residents plus only one type of contact. What kind of join would I use?Residents aID First Name Last name1 Brian Jonestown2 John Paul3 Margaret Attwood4 Michael Irons5 Tammy-Lynn Wynette6 Britney SaxonContacts bID ResidentID Contact Type First Name Last Name1 1 1 Bernie Jonestown2 1 2 Keith Moon3 2 2 John Bonham4 4 1 Diane Irons5 4 2 Grace McMillan6 4 3 Bob Dobelina7 6 1 Morgan Anglo8 6 2 Greg NormandyDesired Results (ALL residents and ‘1’ contact types )a.ID a.First Name a.Last name b.First Name b.Last Name1 Brian Jonestown Bernie Jonestown2 John Baptist NULL NULL3 Margaret Attwood NULL NULL4 Michael Irons Diane Irons5 Tammy-Lynn Wynette NULL NULL6 Britney Welsh Morgan Anglo 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted June 24, 2015 Share Posted June 24, 2015 Either a left join or right join, depending on how you write your query. If you list the residents table first in the query then it will be a left join, because residents is the table on "the left" in the query. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now