Jun 22, 2020 07:00 PM|wavemaster|LINK
I would advise against using email addresses as primary keys.
your SignUp table should look like this
userId int PK (primary key)
then you Wallet table like this:
walletId int PK
userId int FK (foreign key)
The relationship is:
If the user is of Type A then there is 1 wallet
If the user is of Type U then there is no wallet.
A wallet (Type A user) can be seen by multiple Type U users
The query to get the wallet for a Type U user is then:
SELECT walletId, Balance, email, UserType, CreatedBy
FROM Wallet w
JOIN SignUp s ON w.userId = s.CreatedBy
WHERE email = 'the login email from the Type U user'