Skip to content
Advertisement

SQL Query OneToMany Filtering with child entity but returning parent

Hey I need some help with an SQL Query I just can’t figure out. I got these two Tables with an OneToMany/ManyToOne relation:

Now I got this select query to get me all Books that have been written before the current date:

(I’m doing this in Java JPA via the Query Annotation)

In this case I am returning all the books, but what I what instead is:

  1. returning only the authors and without duplicates
  2. Additional I only want to return the authors where the “processed” value is false.

I can achieve the first by doing this or atleast I thought but thats not quite working:

The second condition is pretty simple like this:

So my question is now, how do I and maybe even can I combine these two queries in one query that selects from the book table but only returns the author that are processed = false?

Advertisement

Answer

I’m assuming Book.AUTHOR_ID matches Author.UUID

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement