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

  • SEARCH
  • Home
  • 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 7024097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:47:45+00:00 2026-05-27T23:47:45+00:00

I have 3 tables, usersonline , mobsters , and gangs . I’m trying to

  • 0

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.

  • 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-27T23:47:45+00:00Added an answer on May 27, 2026 at 11:47 pm

    You need a LEFT Join on the Gangs table since “The gang table is optional”

    e.g.

    SELECT m.*, g.* FROM usersonline u 
       INNER JOIN mobsters m ON u.userID = m.id 
          LEFT JOIN gangs g ON g.id = m.gang 
             ORDER BY u.timestamp DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables with decimal numbers and i wnat that there will be maximum
I have tables linked by FK, I query on the first table using entity
I have tables named: Posts_August_2011 Posts_September_2011 Posts_October_2011 Posts_November_2011 Posts_December_2011 Posts_January_2012 I want to create
I have tables: users {id, name} projects {id, name} roles {id, name} projects_users {id,
I have tables Users, Widgets and Layouts. Users have many-to-many relationship with Widgets via
I have tables with listings, categories and one that maps them to each other.
Hi I have two tables (users & friends) I need to connect to the
I have tables of reviews, venues and users. I currently have a _review.html.erb partial
I have a last_action column in my users table that updates a unix timestamp
I have tables with following structure: -- Table structure for table `temp_app` -- CREATE

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.