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)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.