I’m new to SQLite and I’m trying to create a view of joined tables, where table_results references table_names. The user can add, edit and remove items from table_names, but they can not change the references within table_results. What I’m trying to accomplish is that if an entry in table_names is removed, during a JOIN table_names ON (table_results.name_id=table_names._id) will return all rows in table_results, but where a name entry is removed will display “NO NAME”
Example:
table_names:
_id name
1 John
2 Bill
3 Sally
4 Nancy
table_results:
_id name_id score_1 score_2
1 1 50 75
2 4 80 60
3 2 83 88
4 3 75 75
5 2 93 95
where:
Select table_results._id table_names.name, table_results.score_1, table_results.score_2
FROM table_results
JOIN table_names ON (table_reults.name_id = table_names._id);
produces:
1 John 50 75
2 Nancy 80 60
3 Bill 83 88
4 Sally 75 75
5 Bill 93 95
Now if the user was to remove Bill from table_names, the same query string would produce:
1 John 50 75
2 Nancy 80 60
4 Sally 75 75
My Question:
Is there a way to have the query that substitutes values when the join doesn’t find a match? I’d like the above example to produce the following output, but I’m not sure how to write the query string for SQL.
1 John 50 75
2 Nancy 80 60
3 NO NAME 83 88
4 Sally 75 75
5 NO NAME 93 95
Thanks for your help.
Sure, you are doing an inner join, just change it up to a left outer join..