Joining on 3 different keys as they're set I have these tables:

TABLE vessels
ID int PK
organization_id int FK
fleet_id int FK
name VARCHAR

TABLE settings
ID int PK
organization_id int NULL FK
fleet_id int NULL FK
vessel_id int NULL FK
some_value INT


In table settings, some_value can be either 1, 2, 3, 4, 5, 6 or 7

Some entries in the settings table are linked to a vessel_id based on it's fleet_id or organization_id

How do I go about selecting the settings for a vessel, if a vessel has settings via it's fleet_id or organization_id ?
Try this:

SELECT settings.* FROM vessels INNER JOIN settings ON setting.organization_id=vessel.id
UNION
SELECT settings.* FROM vessels INNER JOIN settings ON setting.fleet_id=vessel.id
UNION
SELECT settings.* FROM vessels INNER JOIN settings ON setting.vessel_id=vessel.id