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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:05:37+00:00 2026-05-30T04:05:37+00:00

I have a problem formulating a MySQL query to do the following task, although

  • 0

I have a problem formulating a MySQL query to do the following task, although I have seen similar queries discussed here, they are sufficiently different from this one to snooker my attempts to transpose them. The problem is (fairly) simple to state. I have three tables, ‘members’, ‘dog_shareoffered’ and ‘dog_sharewanted’. Members may have zero, one or more adverts for things they want to sell or want to buy, and the details are stored in the corresponding offered or wanted table, together with the id of the member who placed the ad. The column ‘id’ is unique to the member, and common to all three tables. The query I want is to ask how many members have NOT placed an ad in either table.

I have tried several ways of asking this. The closest I can get is a query that doesn’t crash! (I am not a MySQL expert by any means). The following I have put together from what I gleaned from other examples, but it returns zero rows, where I know the result should be greater than zero.

SELECT id 
  FROM members 
 WHERE id IN (SELECT id 
                FROM dog_sharewanted 
               WHERE id IS NULL) 
   AND id IN (SELECT id 
                FROM dog_shareoffered 
               WHERE id IS NULL)

THis query looks pleasingly simple to understand, unlike the ‘JOIN’s’ I’ve seen but I am guessing that maybe I need some sort of Join, but how would that look in this case?

  • 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-30T04:05:38+00:00Added an answer on May 30, 2026 at 4:05 am

    If you want no ads in either table, then the sort of query you are after is:

    SELECT id
    FROM members
    WHERE id NOT IN ( any id from any other table )
    

    To select ids from other tables:

    SELECT id
    FROM <othertable>
    

    Hence:

    SELECT id
    FROM members
    WHERE id NOT IN (SELECT id FROM dog_shareoffered)
     AND  id NOT IN (SELECT id FROM dog_sharewanted)
    

    I added the ‘SELECT DISTINCT’ because one member may put in many ads, but there’s only one id. I used to have a SELECT DISTINCT in the subqueries above but as comments below mention, this is not necessary.

    If you wanted to avoid a sub-query (a possible performance increase, depending..) you could use some LEFT JOINs:

    SELECT members.id
    FROM members
    LEFT JOIN dog_shareoffered
     ON dog_shareoffered.id = members.id
    LEFT JOIN dog_sharewanted
     ON dog_sharewanted.id = members.id
    WHERE dog_shareoffered.id IS NULL
      AND dog_sharewanted.id IS NULL
    

    Why this works:

    It takes the table members and joins it to the other two tables on the id column.
    The LEFT JOIN means that if a member exists in the members table but not the table we’re joining to (e.g. dog_shareoffered), then the corresponding dog_shareoffered columns will have NULL in them.

    So, the WHERE condition picks out rows where there’s a NULL id in both dog_shareoffered and dog_sharewanted, meaning we’ve found ids in members with no corresponding id in the other two tables.

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

Sidebar

Related Questions

I need some help formulating this query. I have two (relevant) tables, which I
I have the following problem: I have a function which takes a List[Double] as
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run

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.