I have 3 tables, usersonline, mobsters, and gangs.
I'm trying to create a query for the ONLINE USERS page that will run through the records in the usersonline table, linking the IDs to the relevant record in the mobsters table. If the mobster is in a gang, I want it to also grab the record from the gangs table.
Here is my query so far (this doesn't work):
SELECT m.*, g.* FROM usersonline u
INNER JOIN mobsters m ON u.userID = m.id
JOIN gangs g ON g.id = m.gang
ORDER BY u.timestamp DESC
What kind of JOINs should I be using? Is this query even correct?
The gang table is optional but it should always have a record in the mobsters that relates to the usersonline.
Note: My actual query doesn't grab all fields from each table, just did it this way for simplification.
LEFT OUTERtoJOIN gangsand verify the results.