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

The Archive Base Latest Questions

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

A mysql query is vexing me. I have some javascript that lets users assign

  • 0

A mysql query is vexing me. I have some javascript that lets users assign people to a category by moving them back and forth between two buckets (boxes). The first bucket should be all people except those in second bucket (assigned to category). The second bucket consists of people in a category. Therefore, I need a mysql query for the first bucket that pulls all the people except those pulled in the second query (assigned to category).

I have one table of all people and a second of people assigned to categories. (There is also a third table of categories ignored here.) The following code returns the selected group for the second bucket (those in the category) but for the first bucket only pulls those already assigned to some category when I want it to include people who do not even appear in the catpeople table.

I think problem has something to do with NULL or my join but cannot figure it out. Would appreciate any suggestions:

people

id | name

catpeople

id | catid | peopleid

First query should pull all people except those in second query but it only pulls people who show up in catpeople table.

$sql1 = "SELECT * FROM `people` c
LEFT JOIN `catpeople` c 
on p.id = c.peopleid
WHERE catid <> '2'";

Second query works works fine (pulls people in category)

$sql2 = "SELECT * FROM `people` p
LEFT JOIN `catpeople` c 
on p.id = c.peopleid
WHERE catid = '2'";
  • 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-12T11:03:12+00:00Added an answer on June 12, 2026 at 11:03 am

    Having catpeople.catid='2' in WHERE makes your JOIN inner. If you need all people move condition to ON :

    $sql1 = "SELECT * FROM `people` p
    LEFT JOIN `catpeople` c 
    ON (p.id = c.peopleid AND catid <> '2')";
    

    If I understood your question right, you need to modify this query a bit :

    $sql1 = "SELECT p.* FROM `people` p
    LEFT JOIN `catpeople` c 
    ON (p.id = c.peopleid AND catid <> '2')"
    WHERE c.id IS NULL ; -- I guess c.id is a primary key in catpeople.
    --now it returns rows in people table that have no rows 
    --associated with them in catpeople (or rows with catid =2 or catid is null)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MySQL query browser, I manually made a table called users and input some
I have a MySQL query that I am saving to a variable to output
I have a MySQL query that returns a result with a single column of
I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have this MySQL query that I'd like to optimize: SELECT min(`topic_id`) FROM `gallery_topics`
I have a mysql query that throws an error which I'm guessing is because
If I have a MySQL query that contains a union, is there a way
I have a MySQL query that I use to retrieve random rows from a
this is the mysql query SELECT * FROM users AS up JOIN users AS
I have the following mysql query. Could you please tell me how to write

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.