Skip to content
Advertisement

SQL efficient way to match ANY in a large table

I am joining a small table and a very large table and want to return a distinct item if ANY items match. The table is so large that it takes hours for something that I think should take seconds.

The problem is that I am “iterating” over every single entry in the second table. I want to be able to “break” once a condition is met and return that value instead of continuing over every single account.

In the code below, I am finding every single row for each name that I am joining, even though I am only returning the DISTINCT example.name and don’t care about every row. How can I return DISTINCT.name after finding the first instance of new_ex.data = ... after performing the INNER JOIN?

Advertisement

Answer

Without seeing the data it’s hard to be sure this can’t be simplified further, but I think you can at least boil this down to

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