Need some help with a query.. I have three tables.
Source
id name
1 Other
2 Website
3 Wikipedia
Person
id name
1 Tom
2 Lewis
3 Gary
person_source
person_sources_id source_id
1 2
1 3
3 3
I want to build a query that displays a person and a column for each source – displaying the name of the source if it exists in the relationship and a null if it doesnt:
output (for Tom)
-name-
null
Website
Wikipedia
I have the following query, but it gives me the sources attached to the contact, without the nulls..
rs2 = s2.executeQuery("select distinct source.name "+
"from person left join person_source "+
"on person_source.person_sources_id = "+rs.getLong("id")+" join source "+
"on source.id = person_source.source_id");
My code’s current output for Tom:
Output (for Tom)
-name-
Website
Wikipedia
Thanks
if you already know the person id, you don’t need to join
persontable