How to find out if there are intersections of lists in one SQL query

Viewed 52

There is an entity Post that has field List<String> tags

@ElementCollection
@CollectionTable(
        name = "posts_tags",
        joinColumns = @JoinColumn(name = "post_id", referencedColumnName = "id"))
@Column(name = "tag", nullable = false)
private List<String> tags = new ArrayList<>();

There is PostRepositoty that has method

public interface PostRepository extends JpaRepository<Post, Long> {

@Query(
        """
          SELECT ...
        """
    )
    Page<Post> findAllByTagsContaining(List<String> tagsParam, Pageable pageable);


}

Is it possible to get all the posts that have in its tags list at least one element from tagsParam with one only query? Could you help me in this please?

0 Answers
Related