Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6977381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:37:06+00:00 2026-05-27T17:37:06+00:00

I have a query that grabs information from four different tables, and joins them

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:37:07+00:00Added an answer on May 27, 2026 at 5:37 pm

    Well, I don’t think you can do something to greatly improve performance of this query. It looks ok, and even performs great.

    But, if it starts to perform less great, here are steps that I would do:

    1. Break this query in parts. Retrieve guild info in one query, user info in another, etc. Let application code do the joining.

    2. Cache what’s cacheable. I would bet that u.username and f.FlatName don’t change too often, so you can load them once and keep in memory (or memcached).

    Purpose of these changes is to lessen load on the database. App servers (usually) are trivial to scale, just fire up more workers. Database, on the other hand, is one of the hardest to scale components.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query I'm designing which grabs data from multiple different tables. In
I have this rather complex query that grabs data from three tables, and now
I am trying to write a query that grabs information from one database and
I have a simple SQL query in PostgreSQL 8.3 that grabs a bunch of
I have a query that I'm executing from a .NET application to a SQL
I have a query that has 7 inner joins (because a lot of the
I have an array that grabs checkbox data and posts certain information into the
I have the following code that grabs youtube's video id from the old share
Currently we have a solution that grabs the filename from the URL using this
I have a script that grabs data from a MySQL database table and creates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.