JDoe
JDoe

Reputation: 525

SQL doesn't get the correct records

I have a problem with the SQL query below. It gets records that doesn't match certain "requirements".

Lets say the timestamp right now is 1501580316. Then it still returns records with whoisexpire values over this value (such as 1509422400). I think it's conflicting with the AND below with the whoisupdate, because I tried to see what value the whoisupdate was on these records and it returned 0. But I don't get why it still gets it when the AND above doesn't match.

SELECT * FROM domains
    WHERE tld IN ('com')
      AND (whoisexpire !='0' OR whoisexpire<=".time().")
      AND (whoisupdate=0 OR whoisupdate<=".time().")
      AND majrefd>=25
      AND majtf>=10
    ORDER BY whoisexpire
    LIMIT 25

Edit:

This is the SQL Query im trying:

SELECT * FROM domains
    WHERE tld IN ('dk')
      AND ((whoisexpire !=0 OR whoisexpire<=1501586177) AND (whoisupdate=0 OR whoisupdate<=1501586177 ))
      AND majrefd>=25
      AND majtf>=10
    ORDER BY whoisexpire

This is the result: enter image description here

Look at how the values in whoisexpire are over 1501586177, when in fact it shouldn't be possible.

Upvotes: 0

Views: 43

Answers (1)

Matt
Matt

Reputation: 15071

Your bracket order was out, this should fix it.

SELECT * 
FROM domains
WHERE ((whoisexpire !='0' OR whoisexpire<=".time().") AND (whoisupdate=0 OR whoisupdate<=".time()."))
AND majrefd>=25
AND majtf>=10
AND tld IN ('com')
ORDER BY whoisexpire
LIMIT 25

Upvotes: 1

Related Questions