Have 4 relationship tables in my database and want to join them to get the total value… for instance i have friends, family, following and acquaintances and want to join these to get an “ALL” value.
The table formats are as such:
Friends
id follower following
---------------------
1 2 3
2 4 5
Family
id follower following
---------------------
1 5 6
2 7 8
Following
id follower following
---------------------
1 9 10
2 11 12
Acquaintances
id follower following
---------------------
1 13 14
2 15 16
Is the correct query to join all 4 tables…
SELECT following
FROM friends
INNER JOIN family ON friends.following=family.following
INNER JOIN following ON friends.following=following.following
INNER JOIN acquaintances ON friends.following=acquaintances.following
WHERE follower='id'
Basically I want to join and retrieve the “following” value from all four tables where id= my id
Your current query will only list a result if all tables have a link with your friends table. I believe you are more looking for something like this
or a bit nicer to read and easier to adjust at the cost of some performance
UNION