I have a requests
and a results
table. Each with an email_sha256
column.
Requests may contain multiple rows with the same email, while emails are unique in the results. Emails in the results table might not exist in the requests table.
I want to get 100 results that have an email that exists in the requests table:
SELECT results.* FROM results
INNER JOIN requests ON results.email_sha256 = requests.email_sha256
LIMIT 100
This generally works but it may return the same result multiple times if there are multiple requests with the same email. Is there some way to make sure that I get 100 unique results instead of duplicates?
The join seems very slow. Is there some better way to get the desired result. e.g. using
EXISTS
?