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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:05:23+00:00 2026-06-14T03:05:23+00:00

I have coded up an example of exactly what the MySQL query needs to

  • 0

I have coded up an example of exactly what the MySQL query needs to do, I had tried to combine the two queries but I didn’t have any success with doing so. Basically, what this does is selects all users that $session is not friends with already.

I don’t know how much I need to explain as far as my table structure goes, as you can see what I need to do using my query below, but basically my friends table only has one row for each friendship. (a friendship is only valid if the state is 1 and the CASE statement is necessary to get the friends ID from the friendship, since my table does only have one row for a friendship.

$getUsers = mysql_query("SELECT id FROM users WHERE id!=$session");
$getFriends = mysql_query("SELECT CASE WHEN userID=$session THEN userID2 ELSE userID END AS friendID 
                                    FROM friends 
                                    WHERE (userID=$session OR userID2=$session) 
                                    AND state='1'");

        $usersArray = array();
        $friendsArray = array();

        while($usersC = mysql_fetch_array($getUsers))
        {
            $usersID = $usersC['id'];
            array_push($usersArray, $usersID);
        }
        while($usersF = mysql_fetch_array($getFriends))
        {
            $friendID = $usersF['friendID'];
            array_push($friendsArray, $friendID);   
        }

        print_r(array_merge(array_diff($usersArray, $friendsArray), array_diff($friendsArray, $usersArray)));
  • 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-14T03:05:24+00:00Added an answer on June 14, 2026 at 3:05 am

    You want an anti-join, which you can effect through an outer join and a filter for records where the joined table is NULL:

    SELECT users.id
    FROM   users LEFT JOIN friends f
        ON (f.userID = $session AND f.userID2 = users.id AND f.state='1')
        OR (f.userID = users.id AND f.userID2 = $session AND f.state='1')
    WHERE   f.userID IS NULL    AND f.userID2 IS NULL
       AND users.id <> $session
    

    See it on sqlfiddle.

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

Sidebar

Related Questions

my JavaDoc doesn't work when I have a code example with an annotation. Any
I have two pages - a simple HTML code example page from a jQuery
I have a form which writes to a MySQL database. For example: Employee Number:
I want something similar to Mysql's sorting of data, but in jquery. I have
I have looked for a good example of a Builder pattern (in C#), but
Hi I have a code example available here: http://jsbin.com/oxoweh My problem is that I
I have this code (an example that PHP generates for me)... <select id=outsideBlue3> <option
So I have some openGL code (such code for example) /* FUNCTION: YCamera ::
I currently don't have code to show as an example because I been trying
What is the difference between proxy and reify? I have some example code: (.listFiles

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.