I have a table that contains all the data about users. Users can however have multiple email adresses so i need to store them in a seperate table.
I want to run searches based on an email adresses that return all the information about the user. (i also want to be able to search the user table by username which is stored in the user table)
What is the best way to store the email adresses in my database??
I dont think introducing a redundant email adress field in the user table is a good idea, but possibly it is??
for now i have a user table linked to the email table with 1:M relationship.
(so email adress contains user_id as part of its primary key)
after i store the email adresses what is the best way to get all the information with mySql query (so please include mySQL in your answer)
I know about JOIN opperation but i dont know how to use it with this search.
You can store your data like that, assuming all emails are unique (I added
UNIQUE KEYthere)You can retrieve data for specific email like that:
You can also select all emails user have like so: