Querying on jsonArrayFrom
Hi. So i need to fetch posts with comments from a database that are written by a set group of authors and have comments that are written by a set group of people. How would I accomplish this with sql? The best thing I can think of is fetch all posts and comments where the posts are written by the authors, and then do further clientside filtering on the comments - but is there a way to do this with the sql itself?
3 Replies
Another option that I can think of is get post IDs from comments that match the desired comment author IDs and then get the posts from those - but there might be hundreds if not thousands of comments with the IDs
the second solution would probably be something like
like the only issue i see here is that the following subquery might have a lot of results (and might be say 20% of the
comments
table in some cases)
You shouldn't worry about things like that unless you've measured performance problems. All modern databases have a query optimization phase that is usually able handle cases like this. The actual executed code most likely doesn't create a temporary array with 20% of the table's rows, but instead turns that subquery into a join or a semijoin.
okay that makes sense, thanks 👍