I need to achieve a functionality in my project:
I have to select 10 rows from a table having 5 columns and then insert the data in same table after updating 2 columns of the data retrieved (from the select query) …what query will do for achieving the same functionality.
example :(10 rows)
data in column1 is ‘zz’,’zz’,’zz’,’zz’,’zz’,’zz’,’zz’,’zz’,’zz’,’zz’.
data in column2 is ‘ClassA’,’ClassB’,’ClassC’,’ClassD’,’ClassE’,’ClassA’,’ClassB’,’ClassC’,’ClassD’,’ClassE’
INSERT INTO tableT (SELECT * FROM tableT (update column1=’yy’,column2=append ‘_tt’ on the existing data in the rows column))
after firing query, we have 20 records, 10 old and 10 new.
10 new records data will be
column1 is ‘yy’,’yy’,’yy’,’yy’,’yy’,’yy’,’yy’,’yy’,’yy’,’yy’
data in column2 is ‘ClassA_tt’,’ClassB_tt’,’ClassC_tt’,’ClassD_tt’,’ClassE_tt’,’ClassA_tt’,’ClassB_tt’,’ClassC_tt’,’ClassD_tt’,’ClassE_tt’
and the data of other remaining 3 columns will be same
please guide me in framing the query
It depends on the size of your query and on the way you want data to be updated. But for your example you could use
EDIT:
After you changed your question I dont understand what you want to do at all. Please explain this:
because I dont get the pattern.
EDIT 2:
OK. Here we go:
You didnt specify which 10 rows you want. This will select and change firs 10 rows returned by inner select query.