Reputation: 11
I have a table named users with a column id and another grade_id and a table nammed grades with an id and a name.
I want to SELECT all the users with their grades names so i did:
SELECT * FROM users AS u, grades AS g WHERE g.id = u.grade_id
This return all the user with their grades name but it replace user.id by the grade id.
I'm new to sql and i don't know how to make it work, do you have an idea?
Upvotes: 0
Views: 287
Reputation: 29071
Use ALIAS name to column
Try this:
SELECT u.id AS userId, u.name AS userName,
g.id AS gradeId, g.name As grade
FROM users AS u
INNER JOIN grades AS g ON g.id = u.grade_id
Upvotes: 2