mysql - SQL - Inserting data based on multiple criteria -
i'm trying insert number of rows different data based on data in table.
scenario:
i have columns tbl1_action , tbl1_actiondate. want search in tbl2 data in tbl2_reviewdate , tbl2_destroydate. if there data in tbl2_reviewdate need tbl1_action = 'review' , tbl1_actiondate = tbl2_reviewdate. if there data in tbl2_destroydate need another row tbl1_action = 'destroy' , tbl1_actiondate = tbl2_destroydate.
so summarise possible scenarios:
if tbl2_reviewdate null , tbl2_destroydate null insert 1 record tbl1 action , actiondate = null
tbl2_reviewdate not null , tbl2_destroydate null insert 1 row tbl1_action = 'review' , tbl1_actiondate = tbl2_reviewdate tbl2_ null , tbl2_destroydate not null insert 1 row tbl1_action = 'destroy' , tbl1_actiondate = tbl2_destroydate tbl2_reviewdate not null , tbl2_destroydate not null insert 2 rows; 1 tbl1_action = 'destroy' , tbl1_actiondate = tbl2_destroydate , 1 tbl1_action = 'review' , tbl1_actiondate = tbl2_reviewdate. is possible in 1 script? what's best way it?
thanks help
i think want this:
insert table1(action, date) select 'review', actiondate tbl2 tbl2.reviewdate not null union select 'destroy', destroydate tbl2 tbl2.destroydate not null; you 2 separate insert statements.
Comments
Post a Comment