I have 3 tables in sqlite, the first one is about an entity I call bar:
bar
*id
-name
and the other one keeps a relationship between two bars, I call this relationship foo:
foo
*id
-bar_one (fk->bar)
-bar_two (fk->bar)
-baz (fk->baz)
baz holds an attribute that qualifies the KIND relationship that foo represents:
baz
*id
-description
I need to show a query of foo that substitutes the foreign keys with the values of bar an baz, something like:
id bar_one bar_two baz
1 bar1 bar2 siblings
2 bar2 bar3 acquaintances
3 bar3 bar4 enemies
I’m not a specialist in DBs as you can see, I tried with a join and it works with foo and baz.
SELECT foo.id, baz.description FROM foo, baz WHERE foo.baz = baz.id;
But to show the two members of bar is difficult for me in this way. Some advice?
Assuming that columns of table
foo:bar_one (fk->bar),bar_two (fk->bar),bazare non-null columns, you can useINNER JOINto combine both tables, but if they are nullable, useLEFT JOINinstead.basically,
INNER JOINonly displays the rows that a record has atleast one match on every table define, whileLEFT JOINdisplays all rows define on the left hand side whether there is match or none.