I have two tables;
Table A with columns "id", "u_time" (of type datetime), "time_id" (of type int). Table B (which was built as a time dimension), which holds all possible dates between 2000-2010, down to the hour (so, for every date there are 24 rows).
I'm trying to update Table A to have the correct time_id for every id with the following query:
UPDATE A, B
SET A.time_id = B.time_id
WHERE DATE(A.u_time) = B.date
AND HOUR(A.u_time)=B.hour;
However, the query ignores the HOUR condition, and sets all values in A.time_id to the time_id with the correct date but with hour 0.
For example, 2 rows in A that look like this:
Row 1: id=1, time_taken=7/7/2007 01:00
Row 2: id=2, time_taken=7/7/2007 02:00
The query will update the "time_id" column (in A) to the same value - the one that matches the row in B that looks like this:
...... year=2007, month=7, day=7, hour = 00:00
How do I make the query not ignore the different hours?
Thanks
Table A with columns "id", "u_time" (of type datetime), "time_id" (of type int). Table B (which was built as a time dimension), which holds all possible dates between 2000-2010, down to the hour (so, for every date there are 24 rows).
I'm trying to update Table A to have the correct time_id for every id with the following query:
UPDATE A, B
SET A.time_id = B.time_id
WHERE DATE(A.u_time) = B.date
AND HOUR(A.u_time)=B.hour;
However, the query ignores the HOUR condition, and sets all values in A.time_id to the time_id with the correct date but with hour 0.
For example, 2 rows in A that look like this:
Row 1: id=1, time_taken=7/7/2007 01:00
Row 2: id=2, time_taken=7/7/2007 02:00
The query will update the "time_id" column (in A) to the same value - the one that matches the row in B that looks like this:
...... year=2007, month=7, day=7, hour = 00:00
How do I make the query not ignore the different hours?
Thanks