INSERT and SELECT at the same time

wxdqz

New Member
Hi all,

I've checked my manual and the mysql website but i can't figure out a way to:

I have 2 tables;
session_active:
id
session_id
user_id
last_used
session_log:
id
session_id
user_id

I want to select all id, session_id, user_id from session_active where $time - last_used is less than some value, then take those matches from that and shove id, session_id and user_id into session_log table.

I was thinking:

INSERT INTO session_log (id, session_id, user_id) VALUES(SELECT id, session_id, user_id FROM session_active WHERE 'last_used - $time' > 3600)

I quite sure that is wrong, but you can see what I'm getting at.

Thanks heaps for your time,
Billy
 
Back
Top