Reputation: 11117
Let's say I have two tables, c_users
and c_posts
. c_posts
has a foreign key named post_author
that references c_users
.
Example
c_posts : ID = 17, post_author = 550
c_users : ID = 550, user_login = vsg24
I want to write a query to select the all the posts that have a matching user.
This is what I've tried, but got errors:
SELECT c.post_author, d.ID,
FROM c_posts c, c_users d
WHERE c.post_author = d.ID
Also tried:
SELECT c_posts.post_author, c_users.ID,
FROM c_posts INNER JOIN c_users ON c_posts.post_author = c_users.ID
What am I doing wrong? (edit: screenshot included)
https://i.sstatic.net/KQSbc.jpg F https://i.sstatic.net/o5yio.jpg
Upvotes: 1
Views: 55
Reputation: 15071
I assume the errors were because of the extra ,
after the selection fields.
SELECT p.post_author, u.ID
FROM c_posts p
INNER JOIN c_users u ON p.post_author = u.ID
Upvotes: 2