Reputation: 791
I need to join table accounts and table users from my MySQL database.
$sql = "SELECT id FROM `".DB_ACCOUNTS."` WHERE `id` IS NOT NULL ";
table accounts and table users contain a same column as id. I want to get gender, birthday from users and bodybuild, weight, height, ethnictype, skincolor from accounts.
Users Table
Accounts table:
How to do this? Please help.
Upvotes: 0
Views: 68
Reputation:
Change id column in User table with userid.after that you must add userid at Accounts table as Foreign Key. userid column at Account table contain userid value from User table.
ALTER TABLE Accounts
ADD FOREIGN KEY (userid) REFERENCES Users(userid);
sql = "SELECT u.gender,u.birthday,ac.bodybuild, ac.weight, ac.height, ac.ethnictype, ac.skincolor
FROM Users u
LEFT JOIN Accounts ac
ON u.userid=ac.userid
WHERE ac.userid IS NOT NULL; ";
Upvotes: 0
Reputation: 7937
SELECT US.gender, US.birthday,AC.bodybuild, AC.weight, AC.height, AC.ethnictype, AC.skincolor
FROM accounts AC
INNER JOIN users US ON AC.ID=US.ID
You can try above code.
It will helps you.
Upvotes: 1
Reputation: 654
$sql = "SELECT u.gender, u.birthday, a.bodybuild, a.weight, a.height, a.ethnictype, a.skincolor
FROM accounts a
LEFT JOIN users u on a.id = u.id
WHERE a.id IS NOT NULL ";
please try above query...
Upvotes: 0