I'm working with two tables :
-
criter_live
which is automatically updated through AJAX -
worksheets
which is manually updated by a user
So, my issue is, I want to know the differences between the automatically updated table (criter_live
) and the manual updated table (worksheets
). entry_number and left_number are the same in both table, but machine_id
, entry_date
& left_date
could be different, so I want a query to know when there is a difference on worksheets
from criter_live
. Although, a row cannot be in criter_live
but be in worksheets
and conversely. In this case we will make a new record or we'll remove a record from the database.
For example, I'm checking on criter_live
& worksheets
for entry_number
ABC, BUT worksheets
does not contains the latest left_date
value (criter_live
contains the latest value) => print smth to my current user.
I was using this query (for machine_id, for left_date, for entry_date):
SELECT train_id FROM criter_live WHERE entry_date > $currentdate_today_midnight AND mac_id NOT IN (SELECT train_id FROM worksheets)
but it doesn't work as I want... In some cases it doesn't not return the result as I want, I think there is an issue but where... In fact, I can have several machine_id
the same day but however not have the same entry_number
or left_number
... I should mention that in both the tables the fields entry_number
& left_number
contains the same values (except missing line which is not in one of the bases obviously ...).
In concrete cases, if you do not understand:
- Checking criter_live
and worksheets
: left_date
for a certain
entry_number
is different in worksheets
from the ref db criter_live
(applying the
changes on worksheets)
Checking
criter_live
andworksheets
:entry_date
for a certainentry_number
is different inworksheets
from the ref dbcriter_live
(applying the changes on worksheets)Checking
criter_live
andworksheets
: a newentry_number
appears incriter_live
which does not appear inworksheets
: create new row inworksheets
.Checking
criter_live
andworksheets
: aentry_number
no longer appears incriter_live
but exists inworksheets
(deletion of the record inworksheets
)
Thank you
Db scheme:
+--------------------------------------------------------------------------------------+
| criter_live & worksheets |
+--------------------------------------------------------------------------------------+
| id | machine_id | entry_number | machine_type | entry_date | left_date | left_number |
+----+------------+--------------+--------------+------------+-----------+-------------+
| 1 | 76801 | R88901 | -Z | timestamp | timestamp | S79980 |
+----+------------+--------------+--------------+------------+-----------+-------------+
| 2 | 82501 | R89874 | -X | timestamp | timestamp | S98780 |
+--------------------------------------------------------------------------------------+