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 8465237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:59:03+00:00 2026-06-10T14:59:03+00:00

In a tutorial I saw this SQL query: SELECT a.id as a_id, a.info as

  • 0

In a tutorial I saw this SQL query:

SELECT a.id as a_id, a.info as a_info, 
       b.id as b_id, b.info as b_info 
FROM stats AS a 
JOIN stats as b
ON a.id != b.id 
LIMIT 25

The query is working well, but now I would need to add the WHERE condition. I have the table users. The table stats contains the column user_id.
I try to obtain all users from the table stats if users.city=1 (for example), but I still cannot to find a way, how to achieve that…

My problem is, that I currently have no clue, how to put into the query another JOIN (for table users).

I would be grateful for every advice, thank you

  • 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-06-10T14:59:05+00:00Added an answer on June 10, 2026 at 2:59 pm

    Well, as you use the table stats two times in your query, you would actually need two joins for the users table as well. (for stats A and stats B)

    SELECT a.id as a_id, a.info as a_info, 
           b.id as b_id, b.info as b_info 
    FROM stats AS a 
    JOIN stats AS b ON a.id != b.id 
    JOIN users AS a_users ON a.user_id = a_users.id
    JOIN users AS b_users ON b.user_id = b_users.id
    WHERE a_users.city = 1 
       OR b_users.city = 1
    LIMIT 25
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following this tutorial from MSDN. There's something I saw in the code
In one Android Tutorial I saw the usage of this function. There he uses
I saw a tutorial in the web showing you can do something like this
I am reading the Google Go tutorial and saw this in the constants section:
I saw this tutorial for writing a JSON-RPC server for SWI-Prolog. Unfortunately, all it
I saw feeds this word many times in the WCF data service tutorial. But
While reading tutorial for wxWiidgets I saw this Tutorial where author has created 2
How do you do it? I saw one video tutorial on it, but the
This tutorial suggests nesting tables in content controls but every time I'm trying to
ajax tutorial on w3school at http://www.w3schools.com/ajax/ajax_database.asp In this function (function GetXmlHttpObject()), it creates a

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.