如何限制where子句中的join子句

How to restrict join clause via where clause

我有两个 table,commentuser。这是我的结构:

// comment
+----+---------+---------+---------+
| id | id_user | id_post | content |
+----+---------+---------+---------+

// user
+----+------+
| id | name |
+----+------+

我想从 user table(而不是 id_user)访问用户名。这是我的查询:

select c.content, u.name from comment c inner join user u on c.id_user=u.id;

它给了我这个结构:

+---------+------+
| content | name |
+---------+------+

结构很好,但我只需要 select 属于 post x 的评论。换句话说,如何在查询中使用 id_post

如何使用 WHERE 子句:

SELECT c.content, u.name
FROM comment c INNER JOIN user u
ON c.id_user=u.id
WHERE c.id_post = x

您可以使用 where:

select c.content, u.name
  from comment c inner join user u on c.id_user = u.id
  where c.id_post = <x>