I'd like to, when inserting a new record to TABLE 1, assign DATETIME a value based on another tables values, but having trouble putting it all together.
TABLE1 has interval_id and submit_date columns (and many others)
TABLE2 has interval_id, begin_time, and end_time
Example:
- INSERT statement with DATETIME of 2012-10-24 07:29:41
- Peel off just the TIME
- Reference the interval_id's in both tables
- Look up where TIME falls between T2.begin_time and T2.end_time (06:00:00 and 07:59:59 in this case)
- once determined,assign the corresponding value to it in T1.interval_id
So far:
INSERT INTO `TABLE1` (null, now())
WHERE
DATE(submit_date) = curdate()
AND TIME(submit_date)
----not sure on coding here to compare TIME to the begin and end time column data----
full insert statement:
$sql = "INSERT INTO `summary` VALUES (null,'$user_id','$task_id',NOW(),'$tcompleted_id','$minutes_id','$hourinterval_id')
SELECT NOW(), hourinterval_id
FROM `hour_interval` H
WHERE TIME(NOW()) BETWEEN H.start_hour AND H.end_hour LIMIT 1"
INSERTstatement is for new rows only, and therefore has noWHEREclause. Do you mean to update existing rows?INSERTvalues based on the result of aSELECTstatement which would support aWHEREclause.