MySQL Forums
Forum List  »  Newbie

Query ignoring a condition in the "where" clause
Posted by: Amir Yavneh
Date: May 14, 2016 01:42PM

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

Options: ReplyQuote


Subject
Written By
Posted
Query ignoring a condition in the "where" clause
May 14, 2016 01:42PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.