Buying Need Help with MySQL Coding

Discussion in 'Programming' started by mcmuney, Jun 26, 2015.

  1. #1
    What I'm trying to do involves 3 tables:

    Table1: id, status
    Table2: id, value
    Table3: id, value1, value2

    Step1: Pull all unique id numbers where status=1 from Table1
    Step2: For each id pulled in Step1, insert a value=(random number between 1-5; important: the random number should be different for each insert for each id) into Table2
    Step3: For each id and value inserted in Step2, update in Table3 where Table3.id=Table2.id set value1=(existing value +1) and value2=(existing value +the random value inserted in Step2). This will be an update because most of the id's will already exist here and there's only one line per id. However, if id does not exist, it should insert line.

    I'm looking for something quick. Thanks.
     
    mcmuney, Jun 26, 2015 IP