I have 3 tables: user, physician, care_provider that all have a username and email field.
I need to ensure that the username and email created for any of the 3 user types is unique across all 3 tables.
Is there a way to join or union the tables to check for the same data in each?
Obviously I could do 3 selects, but of course I'd prefer to check the username with a single query.
Right now I'm just checking all 3 like so:
$count = 0;
$user = $this->db->query("
SELECT COUNT(user_id) AS total
FROM " . DB_PREFIX . "user
WHERE username = '" . $this->db->escape($username) . "'
");
if ($user->row['total']):
$count += $user->row['total'];
endif;
... (for each table) ...
return $count;