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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:22:15+00:00 2026-05-29T06:22:15+00:00

I have a query that retrieves the users that are online, and a users

  • 0

I have a query that retrieves the users that are online, and a users friends. Now I want to know the best way to combine the two so I can get the results of the users friends that are online.

Friends query:

 SELECT 
       CASE WHEN userID=$session 
       THEN userID2 
       ELSE userID 
       END AS friendID 
 FROM friends 
 WHERE userID=$id OR userID2=$session
 LIMIT 18

users online:

SELECT * 
FROM usersActivity 
WHERE setActivity!=3 
AND userID!=$session

usersActivity.userID needs to match friendID

  • 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-29T06:22:16+00:00Added an answer on May 29, 2026 at 6:22 am

    Query should be:

    SELECT users.name
    FROM usersActivity
    INNER JOIN friends ON
        (usersActivity.userID = usersActivity.userID AND usersActivity.userID2 = $session) OR
        (usersActivity.userID2 = usersActivity.userID AND usersActivity.userID = $session)
    INNER JOIN users ON
        (usersActivity.userID = users.userID) OR
        (usersActivity.userID2 = users.userID)
    WHERE usersActivity.setActivity!=3 
        AND usersActivity.userID!=$session
        AND users.userID != $session
    GROUP BY users.id
    

    You may use COUNT(user.id) if you want only count of users. Or select all names (store them for later use in listing) and use only mysql_num_rows() for getting actual number of friends online

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

Sidebar

Related Questions

I have a query that retrieves 1000 records and user can add a new
I have the following query that retrieve the number of users per country; SELECT
I have two tables users registered_members I want to confirm values from user table
I have two situations in this case: I want to query a WCF service
Let's say I have two or more tables filled with users and I want
I have a query that retrieves location entities within a certain radius given a
I have a very simple SQL query that I made which retrieves some user
I have a query that retrieves the name of each friend a user has
i have a query that returns some users related to a specific user (Bob).
I have two tables, users and hra. A user can only have one record

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.