Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting Duplicate rows by updating its value in MYSQl
    primarykey
    data
    text
    <p>I have a very complex table which is like this :-</p> <pre> Snos Column1 Column2 Column3 Column4 Column5 Column6 1 AD AD1 C1 2011 P1 6435200 2 AD AD1 C1 2010 P1 234 3 AD AD1 C1 2009 P1 6435 4 BD AD2 C2 2010 P2 198448333 5 CD AD3 C3 2011 P3 194414870 </pre> <p>Now, I need to process a query that should duplicate a row where suppose p2 value is not available for that particular year or for from any of 2009 or 2010 or 2011 and put last column's value as zero in it.</p> <p>So now my database should look like -</p> <pre> Snos Column1 Column2 Column3 Column4 Column5 Column6 1 AD AD1 C1 2011 P1 6435200 2 AD AD1 C1 2010 P1 234 3 AD AD1 C1 2009 P1 6435 4 AD AD1 C1 2011 P2 0 5 AD AD1 C1 2010 P2 0 6 AD AD1 C1 2009 P2 0 7 AD AD1 C1 2011 P3 0 8 AD AD1 C1 2010 P3 0 9 AD AD1 C1 2009 P3 0 10 BD AD2 C2 2010 P2 198448333 11 BD AD2 C2 2009 P2 0 12 BD AD2 C2 2011 P2 0 13 BD AD2 C2 2010 P1 0 14 BD AD2 C2 2009 P1 0 15 BD AD2 C2 2011 P1 0 16 BD AD2 C2 2010 P3 0 17 BD AD2 C2 2009 P3 0 18 BD AD2 C2 2011 P3 0 19 CD AD3 C3 2011 P3 194414870 20 CD AD3 C3 2009 P3 0 21 CD AD3 C3 2010 P3 0 22 CD AD3 C3 2011 P1 0 23 CD AD3 C3 2009 P1 0 24 CD AD3 C3 2010 P1 0 25 CD AD3 C3 2011 P2 0 26 CD AD3 C3 2009 P2 0 27 CD AD3 C3 2010 P2 0 </pre> <p>I tried using temporary table like </p> <pre> CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM table WHERE *Some Condition*; Some If Else Then UPDATE tmptable_1 SET Column6 = 0; INSERT INTO table SELECT * FROM tmptable_1; DROP TEMPORARY TABLE IF EXISTS tmptable_1; </pre> <p>but its not working. Can any one help me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload