<p>I need to construct some rather simple SQL, I suppose, but as it's a rare event that I work with DBs these days I can't figure out the details.</p>

<p>I have a table 'posts' with the following columns:</p>

<blockquote>
  <p>id, caption, text</p>
</blockquote>

<p>and a table 'comments' with the following columns:</p>

<blockquote>
  <p>id, name, text, post_id</p>
</blockquote>

<p>What would the (single) SQL statement look like which retrieves the captions of all posts which have one or more comments associated with it through the 'post_id' key? The DBMS is MySQL if it has any relevance for the SQL query.</p>

You're basically looking at performing a subquery --
```
SELECT p.caption FROM posts p WHERE (SELECT COUNT(*) FROM comments c WHERE c.post_id=p.id) > 1;
```
This has the effect of running the
```
SELECT COUNT(*)
```
subquery for each row in the posts table. Depending on the size of your tables, you might consider adding an additional column,
```
comment_count
```
, into your
```
posts
```
table to store the number of corresponding
```
comments
```
, such that you can simply do
```
SELECT p.caption FROM posts p WHERE comment_count > 1
```