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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:43:37+00:00 2026-06-18T21:43:37+00:00

Assume that I have 2 tables named aTable1, aTable2 aTable1 has userID set to

  • 0

Assume that I have 2 tables named aTable1, aTable2

aTable1 has userID set to identity and contains the following data:

userID  email          FirstName    LastName
1       NULL               C            CC
2       NULL               D            DD
3       a@yahoo.com        A            AA
4       b@yahoo.com        B            BB
5       e@yahoo.com        E            EE
6       f@yahoo.com        NULL         NULL
7       g@yahoo.com        NULL         NULL

aTable2 contains the following data:

userID  email          FirstName    LastName    Title
3       a@yahoo.com      A            AA       student
4       b@yahoo.com      B            BB       student
5       e@yahoo.com      E            EE       student
NULL    NULL             C            CC       dean
NULL    NULL             D            DD       advisor
NULL    f@yahoo.com NULL    NULL               student2
NULL    g@yahoo.com NULL    NULL               student3

I want to update aTable2.userID based on aTable1, but knowing that 2 tables have null values in it, so i do like this:

set ANSI_NULLS off
update aTable2
set aTable2.userID = a.userID
from aTable a, aTable2 b 
where a.FirstName = b.FirstName and a.LastName = b.LastName and a.email = b.email

However, what this update does not update all the userID, in fact, it only updates those that have email not equal to null, but I already set ANSI_NULLS to off.
What did I do wrong?

  • 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-18T21:43:38+00:00Added an answer on June 18, 2026 at 9:43 pm

    To get your update query to work, you can try something like this:

    UPDATE a2
    SET
       userId = a.UserId
    FROM
        aTable2 a2
        JOIN aTable1 a ON 
            ISNULL(a.Email,'NULL') = ISNULL(a2.Email,'NULL') AND 
            ISNULL(a.FirstName,'NULL') = ISNULL(a2.FirstName,'NULL') AND
            ISNULL(a.LastName,'NULL') = ISNULL(a2.LastName,'NULL')
    

    When the values are NULL, I’ve arbitrarily set the value to ‘NULL’ — use some distinct value that will not appear in your data to ensure you won’t receive false positives.

    I’ve also seen other solutions using OR criteria in the JOIN and checking both values for NULL:

    ((a.Email = a2.Email) OR (a.Email IS NULL AND a2.Email IS NULL)) ...
    

    Good luck.

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

Sidebar

Related Questions

Let's assume that I have 2 tables: Human, Car. Table Car has some columns
I have a city table that has two columns from_city to_city now lets assume
Assume that I have a backbone model that has a bunch of boolean attributes:
To illustrate, assume that I have two tables as follows: VehicleID Name 1 Chuck
I have the next task. Let's assume that we have below tables in a
Assume that we have two tables: Roles and Reports . And there exists a
Assume that I have 2 tables : members and orders (Mysql) Members : id
Let's assume I have 3 tables in a MySQL table with the following fields.
Assume I have the following tables: tableA a_name | age | country Jordan |
Let's assume that I have mytable in mySQL CREATE TABLE `mytable` ( `gender` enum('MALE','FEMALE','UNISEX')

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.