0

i have list in data_1 table. i want to select highest value item in one group and update it to another table. can i do that with 1 query?

example : Select "Group B Leader Jane" and update it to other table with coulmns

Table 1 : data_1

id(ai) - group - name - serial - point
52        A      Jhon    A54V     14
53        A      Arthur  B896     11
54        B      Jane    RT3A     14
55        B      Kim     RF31     13

After UPDATE -> Table 2 : data_2

id(ai) - name - text1 - text2
8        Jane   RT3A      14
1

In this case you can use INSERT INTO ... SELECT FROM ... ORDER BY DESC LIMIT 1:

INSERT INTO data_2 (name, text1, text2)
SELECT name, serial, CAST(point AS varchar(10))
FROM data_1
ORDER BY point DESC
LIMIT 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.