Getting duplicates in WHERE clause results (subquery)

Hello,

I hope i can explain my problem:

Let’s say i have a Movies table and a Genres table:
MovieTable

  • genres [n] (each movie can have more than 1 genre)

GenreTable

  • description

Let’s say i have 3 movies in DB : Movie1 has [Action], Movie2 has [Comedy], Movie3 has [Action, Comedy].

How would i write the subquery for the WHERE clause, if i wanted all the movies where genres are ‘Action’ OR ‘Comedy’, without getting duplicate results?

Because right now, if i write in the where clause ‘genres.description=‘Action’ OR genres.description=‘Comedy’’, Movie3 appears in results twice.

I’m developing web app in Javascript, btw.

Thank you!

Hi Diogo,

I just tried the following where clause query in your Movie table and I didn’t get any duplicates:

Subgenres.Description in ('Thriller', 'Action', 'Sci-Fi')

Please give it a try and let me know if it works for you.

Regards,
Mark

1 Like

Hi Mark,

Thank you :slight_smile: I will try and get back to you!

So, on the REST console i was not getting duplicates too, but i was still getting on my frontend app duplicates.

Then, i inspected the queryBuilder, and the distinct was “false” by default.

So, i did queryBuilder.setDistinct(true), and now it doesn’t show duplicates.

Thank you.

1 Like