php - insert into with 2 joins? -
i have 1 table auction_activity_notifications
need insert id users
table , column item_watch
, need join email_templates
table , need insert auction_activity_notifications
i make query inserting id of user , item_watch column , need join email_templates
, insert id email_templates
auction_activity_notifications
insert auction_activity_notifications (id_user, id_target) select id, item_watch users u left join auction_activity_notifications aa on u.id = aa.id_user , u.item_watch=aa.id_target
i have these columns in auction_activity_notifications
and in end need insert current date created_date_time
id_email_templates, id_user , id_target , created_date_time
add 1 more join in query
insert auction_activity_notifications (id_email_templates,id_user, id_target,created_date_time) select et.id,u.id, u.item_watch ,now() users u left join auction_activity_notifications aa on u.id = aa.id_user left join email_templates et on (aa.id_email_templates=et.id) , u.item_watch=aa.id_target
note use table aliases column names when columns same in joined tables protects ambiguous condition columns
for current datetime can use datatype
timestamp
, set table column default value setting current_timestamp
, remove now()
select , created_date_time
insert , automatically add current timestamp when , record inserted
alter table `table` change `created_date_time` `created_date_time` timestamp default current_timestamp not null;
Comments
Post a Comment