php - I have question regarding SQL and phpmyadmin queries
Solution:
Each of your table should have Primary key. Primary Key is the unique id (could be number or string or even uuid. Ex: ShopOwner_Id) which could be used to fetch any row in the table. This primary key is used to establish relationships between tables.
Also for relationships there could be 3 types of major relationships between two tables.
- One to One
- One to Many or Many to One
- Many to Many
For example,
lets say you have two tables UserLogin and UserProfile. UserLogin contains -> id, email, password, and verified. Whereas UserProfile contains -> id name, address, mobile, dob, etc. Here Each UserLogin will have single UserProfile whereas each UserProfile will have only one UserLogin. So they have One to One relationship. In this case, You add the foreign key to the both tables. You will add profile_id as foreign key in UserLogin whereas login_id in UserProfile.
Lets say, you have two tables
Shop
andUser
. Where eachShop
will belong to a singleUser
(in your case shopowner) But aUser
can have multipleShops
. In this case,Shop
andUser
have Many to One relationship (orUser
andShop
have One to Many relationship). In this case we add a foreign key of user_id (which is primary key ofUser
table) toShop
table.
In your case I will suggest to only keep email and password in shopOwner_login
table and add its foreign key to shop_details
table. This way your data will be normalize and you will not have to make sure to maintain same data in multiple tables.
Answer
Solution:
So,d query need to fetch the data looks like - SELECT a.ShopOwner_email Shop_Pass as EmailId,a.Shop_Pass as Password FROM shop_details as a left join shopOwner_login as b on b.ShopOwner_Id = a.ShopOwner_Id