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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:14:13+00:00 2026-05-24T04:14:13+00:00

This seems so basic, I’m flabbergasted for lack of a better word. I have

  • 0

This seems so basic, I’m flabbergasted for lack of a better word. I have two tables, let’s call them albums and artists

CREATE TABLE `albums` (
  `album_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `artist_id` bigint(20) DEFAULT NULL,
  `name` varchar(200) NOT NULL,
  PRIMARY KEY (`album_id`)
)
CREATE TABLE `artists` (
  `artist_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  PRIMARY KEY (`artist_id`)
)

There are a few hundred thousand reconds in each table. Some of the album rows have a null artist_id, this is expected.

However, when I perform the following query to find artists without albums:

SELECT * FROM artists WHERE artist_id NOT IN (SELECT artist_id FROM albums)

… the query returns zero results. I know that this is not true. So I tried this one:

SELECT * FROM artists WHERE artist_id NOT IN (SELECT artist_id FROM albums WHERE artist_id IS NOT NULL)

… and I get back a couple thousand rows. My question is: Why did the first query seem to operate on the idea that any number = NULL? Or is this an odd effect that NULL has on the IN() statement? I feel like this is something basic that I’ve missed. I don’t usually use NULL in my db tables at all.

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

    This is why NOT EXISTS is semantically correct

    SELECT * FROM artists ar
    WHERE  NOT EXISTS
       (SELECT * FROM albums al WHERE ar.artist_id = al.artist_id)
    

    Logic:

    • NOT IN (x, y, NULL) is actually
      • NOT (x OR y OR NULL) is actually
        • (NOT x) AND (NOT y) AND (NOT NULL)

    So NULL invalidates the whole NOT IN

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

Sidebar

Related Questions

So this seems pretty basic but I can't get it to work. I have
This seems basic, but can't seem to find a way to implement this: I
This seems very basic and I must be missing something, but here goes anyways...
This seems like a basic question, but I haven't found any clear answers. Essentially,
This seems like a basic question, but it's still bugging me. Why doesn't MyObject
This may seem like a basic question. I have a light-weight website and would
This seems basic, but I want to display a representation of some CLR objects
This seems so basic but for some reason I can't get it to work
This seems very basic but I can't figure it out. I've got a table
This seems like a very basic question but I couldn't find any help on

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.