Skip to content
Advertisement

MYSQL select name from id [closed]

I need to get the name from the author id in table post.

I have these 2 tables:

post:

id authorID title
1 3 Header title Example

and users:

id author [..]
1 Dennis
2 Alexa
3 Roger

My SQL:

SELECT author
FROM users
WHERE authorID = users.id

any suggestions?

the solution is:

SELECT id, (SELECT author FROM users WHERE id = p.authorID) 
FROM users
WHERE authorID = users.id

Advertisement

Answer

SELECT u.author AS author_name
FROM users u
INNER JOIN post p
ON u.id = p.authorID;
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement