I have a query that grabs information from four different tables, and joins them all. The tables are 'guilds', 'guilds_memberships', 'flats', and 'users'. The query I have works, but i'm just wondering about the efficiency of it and if it can be made faster.
I mean at the moment it works fine and is speedy, but there isn't much data inside of guilds_memberships, and it's being COUNTED()'d. The query i'm using is shown below. (there will always be at least 1 record for each guild inside of guilds_memberships, flats, and users btw, if that'll help with optimization at all (no reason to check for NULLs))
SELECT g.id, g.roomid, g.ownerid, g.roomid, g.state, g.name, g.description, g.badgestring, g.primarycolour, g.secondarycolour, g.created, u.username, f.FlatName, COUNT( m.guildid ) AS Members
FROM guilds g
INNER JOIN users u ON u.id = g.ownerid
INNER JOIN flats f ON f.FlatID = g.roomid
INNER JOIN guilds_memberships m ON m.guildid = g.id
WHERE g.id =1
LIMIT 0 , 30