I have two tables in a SQLite DB, and both have the following fields:
idnumber, firstname, middlename, lastname, email, login
One table has all of these populated, the other doesn’t have the idnumber, or middle name populated.
I’d LIKE to be able to do something like:
select idnumber, firstname, middlename, lastname, email, login
from users1,users2 group by login;
But I get an “ambiguous” error. Doing something like:
select idnumber, firstname, middlename, lastname, email, login from users1
union
select idnumber, firstname, middlename, lastname, email, login from users2;
LOOKS like it works, but I see duplicates. my understanding is that union shouldn’t allow duplicates, but maybe they’re not real duplicates since the second user table doesn’t have all the fields populated (e.g. “20, bob, alan, smith, bob@bob.com, bob” is not the same as “NULL, bob, NULL, smith, bob@bob.com, bob”).
Any ideas? What am I missing? All I want to do is dedupe based on “login”.
Thanks!
As you say
unionwill remove duplicate records (note thatunion allwon’t!). Two records are considered duplicates when all their column values match. In the example you considered in your question it is clear thatNULLis not equal to20or'alan'so those records won’t be considered duplicates.Edit:
That is not necessary. I think you can do the following:
However, if you’re sure that you only have different values on
idnumberandmiddlenameyou can max only those fields and group by all the rest.