I am writing an query to select player bans from another table but firstly its very slow taking around 7-14 seconds and secondly its returning invalid rows.
The first query is as follows:
SELECT *
FROM sourcebans.sb_bans
WHERE removetype IS NULL
AND removedon IS NULL
AND reason NOT LIKE '%[FragSleuth] Duplicate account%'
AND ip IN(SELECT DISTINCT ip
FROM fragsleuth.history
WHERE trackingid = "ad000c3803b48190aabf382e01b957c9")
OR authid IN(SELECT DISTINCT steamid
FROM fragsleuth.history
WHERE trackingid = "ad000c3803b48190aabf382e01b957c9")
The second query is as follows
SELECT * FROM `history` WHERE trackingid = "ad000c3803b48190aabf382e01b957c9"
And a couple of screenshots to show what I mean: First Query Second Query
In screenshot 1 you can see that its returning a row where the removedon and removetype is not null when I asked the query to only return rows with NULL.
I am also afraid that inside the history table there will be duplicate entries for the steamid and ip columns which might make the query slow, is there any way to make the query only select rows with a unique ip or steamid based on the trackingid?
Any help would be much appreciated.
Thanks
Edit: I am overwhelmed by the help, Thanks to @maraca, @Skorpioh and @Adam Silenko, the query time is now less than a second!