Reputation: 55
So maybe it's due to lack of sleep, but I am having a major brain malfunction and can't remember what is going wrong here. Here is my statement:
SELECT DISTINCT `county`, COUNT(*)
FROM `ips`
WHERE `county` != 'NULL' AND `county` != '' AND
EXISTS (SELECT * FROM `pages`
WHERE (`timestamp` BETWEEN FROM_UNIXTIME(?) AND FROM_UNIXTIME(?)))
GROUP BY `county`
I'm expecting the results to be something like:
County | Number
Some county | 42
Other county | 27
My pages table has a timestamp of each time a page is viewed by a user, so if they viewed a page between the date, the county from the IP table is selected and the number of that total county is being populated as the num. I'm using PDO and i'm passing in two times that I've used strtotime()
on.
I'm currently stuck. All help is apprieciated. Hopefully it's not some stupid little mistake that I've overlooked.
Upvotes: 0
Views: 37
Reputation: 37023
You cant compare null with !=
you need to use is not null.
SELECT `county`, COUNT(*)
FROM `ips`
WHERE `county` IS NOT NULL AND `county` != '' AND
EXISTS (SELECT 1 FROM `pages`
WHERE (`timestamp` BETWEEN FROM_UNIXTIME(?) AND FROM_UNIXTIME(?)))
GROUP BY `county`
Upvotes: 1