It would probably be much better for you to normalize administrators, users, managers, and what you want into one single table with a column of the Role discriminator, which would save a lot of duplication, which is essentially the reason for normalization in the first place. You can then add role details to the different tables that you use with the User table in the join.
Your request may look as simple as:
SELECT `Name`, `Surname`, `Email`, `Phone`, `Role` FROM `User` WHERE `User`.`Role` IN('Administrator','Manager','Customer', ...)
Which is also easier to process the database than union s
If you take one more step, you can add a UserRoleCoupling table (instead of the Role column in User ) that contains all the roles that the user has for each user:
CREATE TABLE `UserRoleCoupling` ( UserID INT NOT NULL,
And put the actual role information in a separate table:
CREATE TABLE `Role` ( ID INT NOT NULL UNIQUE AUTO_INCREMENT, Name VARCHAR(64) NOT NULL PRIMARY KEY (Name) )
Now you can have multiple roles per user and use queries such as
SELECT `U`.`Name` ,`U`.`Surname` ,`U`.`Email` ,`U`.`Phone` ,GROUP_CONCAT(`R`.`Name`) `Roles` FROM `User` INNER JOIN `UserGroupCoupling` `UGC` ON `UGC`.`UserID` = `User`.`ID` INNER JOIN `Role` `R` ON `R`.`ID` = `UGC`.`RoleID` GROUP BY `U`.`Name`, `U`.`Surname`, `U`.`Email`, `U`.`Phone`
Which gives you the basic User data and a comma-separated list of all Role names assigned.
In general, the best way to normalize the database structure is to make the tables as universal as possible without being redundant, so do not add data about administrators or clients to the user table, but use the connection between User and Administrator to find specific details of the administrator . The way you do it now is not really normalized.
I will see if I can find my favorite book on database normalization and publish ISBN when I have time later.