MySQL Forums
Forum List  »  Newbie

Re: unique IDs from two tables
Posted by: Peter Brawley
Date: June 10, 2014 01:14PM

Quote

users that get more than one answer are recorded in a separate table, with one record per answer. Users.ID and Conflicted_Users.UserID are equivalent.

I want to count the number of users that took the test regardless of whether they're conflicted

If that's so, you can ignore the conflicted_users table.

But you show a row in conflicted_users that does not appear in users, so the data you posted contradicts the description you provide.

Same self-contradiction problem with the data model---it makes zero sense to record the first test score in one table and subsequent test scores in another. You need something like ...

users(userid PK)
test(testid PK, userID, score, date)

So the answer is, fix the data design.

Till then, if the posted data is correct use ...

select count(distinct userid) from (
  select distinct userID from users
  union
  select distinct userID from conflicted_users
) u;

and if the description is correct, use ...

select count(distinct userid) from users;

Options: ReplyQuote


Subject
Written By
Posted
June 10, 2014 11:53AM
June 10, 2014 11:58AM
June 10, 2014 12:15PM
Re: unique IDs from two tables
June 10, 2014 01:14PM
June 10, 2014 02:06PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.