Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vidhyaprakash85's avatar

Query Optimization

I have an sql query and it need optimization because even after 20 mins no update

UPDATE
	`exam_application_fees`,
	`exam_applications`
	INNER JOIN `exam_application_fees` eaf ON eaf.`student_id` = `exam_applications`.`student_id`
SET
	`exam_application_fees`.`total_paper_amount` = (
		SELECT
			DISTINCT SUM(`paper_amount`)
		FROM
			`exam_applications`
		WHERE
			`student_id` = `exam_application_fees`.`student_id`
	)
0 likes
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@vidhyaprakash85 How about this one?

UPDATE 
    exam_application_fees eaf
SET 
    eaf.total_paper_amount = (
        SELECT SUM(paper_amount)
        FROM exam_applications
        WHERE student_id = eaf.student_id
    )
1 like

Please or to participate in this conversation.