使用多个表删除和更新查询

时间:2015-06-30 11:48:17

标签: mysql sql

我有以下select语句:

select  *
from    (   select  q.*,
                qg.index_min as groupIndexMin,
                qg.index_max as groupIndexMax,
                fo.form_condition,
                fo.form_array,fo.form_index
            from question_group qg, question q
            right join form fo on q.form_id = fo.form_id
            where q.form_id=14 and
                 (q.question_group_id=qg.question_group_id and q.question_type_id NOT IN(12))
            order by question_order) m
 left join (select  r.response_text,
                    r.response_id,
                    r.response_index,
                    f.*,
                    a.*
             from   response r
             right outer join field f on r.field_id=f.field_id and r.response_index=5
             right outer join application a on r.application_id=a.application_id
             right outer join user u on a.user_id=u.user_id
             where  (a.application_id=70 and u.user_id=47)) n on m.field_id = n.field_id
order by m.question_order ;

现在我需要,

  1. 删除查询:对于上述使用相同条件的选择查询,记录将被删除,其中response_index = 5.

  2. 更新查询:假设,如果我删除response_index = 5,则会更新剩余的response_index。例如,response_index = 6 => response_index = 5和response_index = 7 => response_index = 6就是这样。

  3. 请帮帮我。

0 个答案:

没有答案