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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:33:22+00:00 2026-05-17T15:33:22+00:00

I need to figure out some clever MySQL snippet that will allow me to

  • 0

I need to figure out some clever MySQL snippet that will allow me to easily see two tables, the ids in the table if they exist or NULL or empty if they don’t exist.

I have a users table and a legacy table and outside of manual comparison I can’t figure out how to make them appear in a table together so I can compare. What I would love to see is something like this:

+----------------------------+
| user_id | email     | uid  |
| 14      | me@me.com | 26   |
| 16      | ug@ug.com | NULL |
+----------------------------+

I know there’s a way to include NULL or empty values but I’m not sure what it is. Here’s my deranged SQL query so far, yes, I know it’s horrible to do subselects inside of subselects:

select uid from users where mail IN (
    select email from legacy_users where id NOT IN (
        select sourceid from migrate_map_users
    )
);

There are three tables involved here, legacy_users => migrate_map_users => users. The middle is just an m2m which joins the two. legacy_users and users both have an email column. and their own version of an id.

Thank you 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-17T15:33:22+00:00Added an answer on May 17, 2026 at 3:33 pm

    You need to learn about join types, in particular left and outer joins:

    SELECT u.uid, u.mail, lu.id
    FROM users u
    LEFT OUTER JOIN legacy_users lu 
        ON u.email = lu.mail
    WHERE lu.id NOT IN
       (
            SELECT sourceid 
            FROM migrate_map_users
        );
    

    The LEFT OUTER JOIN will make sure all records in the LEFT table will be returned, whether there is a corresponding one in the right one or not.

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

Sidebar

Related Questions

EXAMPLE: http://jsbin.com/ewiko4/5/ So I have some Dynamic divs that I need to figure out
Hey all i am in need of some help trying to figure out how
I need to figure out a way to set ValidateRequest at model...I understand that
I understand that I need to figure out my own homework, but seeing that
Hi so i'm doing some test prep and i need to figure out parts
I need to figure out which part of a linux program that I am
I've got a stored procedure in my MySQL database, and need to figure out
I need to set my RewriteLogLevel in MAMP to figure out some mod_rewrite problems.
I need to figure out how long some code is taking in Velocity (VTL).
I need to figure out how to do some C# code in php, and

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.