I’m trying to select MerchantIDs that are the same but have different Networks values, for example:
ID MerchantID Network
1 1 A
2 1 A
3 2 B
4 2 C
5 3 D
6 3 D
In that case I would like the query to return “2” (since it’s the only MerchantID that have different Networks).
Until now I have the following query:
SELECT a.MerchantID
FROM table a
JOIN table b
ON a.ID = b.ID
AND a.Network <> b.Network
AND a.MerchantID = b.MerchantID
GROUP BY a.MerchantID
Thing is table have around ~43,000 records and that query takes a LOT of time (haven’t been even able to get the results).
Is there any better way to do it?
Thanks.
Try this:
this should be faster, joins that use
<>conditions are (usually) slower.