Skip to content
Advertisement

How do I do this without a subquery?

enter image description here

I need to make the same query, but without a subquery!

I need to get the count of rows in which genre_id is equal to the :deletedGenreId and the org_type_id value of this line in this table is not unique

Advertisement

Answer

There is nothing wrong with sub-query. Sub-query actually can help boost performance and increase code readability if you do it correctly. It is indispensable for complicated logic.

What we generally want to get rid of is correlated sub-query, like the one in your script. The following query implement the same logic as yours without correlated sub-query:

If the table is big, there are many different org_type_id, and deletedgenreid is very selective, your script will actually have better performance. It all depends on the volume of data the query needs to touch.

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