0

I've been trying to understand how this works, and so far, I found a workaround but it's not as nice as I had hoped.

Say I get some resultset from a query like so:

SELECT id FROM photos WHERE some clause

And I'd like put the resultset in a where clause like so:

SELECT * FROM tags WHERE photo_id IN ( array I just received )

How would I do this with a nested query? I tried looking up subqueries to no avail. Joins are not my strong suit but I fear I will need them in this case.

1 Answer 1

2
SELECT * FROM tags WHERE photo_id IN (SELECT id FROM photos WHERE some clause)

but this should also work:

SELECT tags.* FROM tags INNER JOIN photos ON (tags.photo_id=photos.id AND some clause)
Sign up to request clarification or add additional context in comments.

1 Comment

Okay so I was right in both hunches.. thanks a bunch, will test now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.