moderns — 2013-06-21T19:42:57-04:00 — #1
I want to make a conditional SQL. I have one table "users" and it has two columns (id, status)
I need to search for users IDs based on their status. For example.
Every 5 seconds I am querying from the database (by AJAX) as per the below description:
Let us say that I have the below results on my wall (on html):
I need to get IDs from table "users" but exclude the IDs from database if their statuses haven't changed on my wall.
So the algorithm should be:
Get all IDs from table "users" but exclude the IDs (1,2) from database (if and only if) their status = ("A", "B").
Simply, I need to retrieve all IDs including the IDs (1,2). But for the IDs (1,2): I need to retrieve them in case their corresponding statuses are NOT EQUAL ("A", "B") respectively.
But for IDs other than (1,2) like (3,4,5,...), I need to retrieve them without any condition.
I would greatly appreciate if the solution provides an excellent performance when the database records are huge and the check every 5 seconds.
Thanks in advance.
guido2004 — 2013-06-22T07:10:58-04:00 — #2
Get them all, and do the check for changed status in your scripting language?
moderns — 2013-06-22T10:53:22-04:00 — #3
Thanks for your reply. I don't want to do any check and filtering in PHP. I need to do everything in Mysql query.
kylewolfe — 2013-06-26T16:14:35-04:00 — #4
I think we need a little more info here. Why not just query all where status not in ('A', 'B')
moderns — 2013-06-27T00:34:21-04:00 — #5
Thanks for your reply. No, I need to exclude the records which have no status changed. But if the status changed for those records, then I need to get them.
kylewolfe — 2013-06-27T09:21:50-04:00 — #6
And where is the original data stored at to compare to the new? If you save a status change date, you can ensure that the change had occurred in the last n seconds. However you would have to run a different query to populate your original data set.
moderns — 2013-06-27T19:45:36-04:00 — #7
Status now: "hello"
Status after 1 second: "hello 2"
Status after 2 seconds: "hello" ==>same as the first one.