This is the sql based question give me the best so...

Creato il: 7 novembre 2026

Risposto usando GPT-6 Thinking da Chat01

Domanda

IMG-20261107-WA0067.jpg
IMG-20261107-WA0068.jpg
IMG-20261107-WA0069.jpg
IMG-20261107-WA0070.jpg

This is the sql based question give me the best solution for this without eror

Pensiero

Worked for a couple of seconds

Risposta

Text version

Here is the correct MySQL solution for your CodeSignal SQL question. It uses NOT EXISTS to find candidates who have never received a detention.

Final SQL code (copy and paste)

sql
CREATE PROCEDURE solution() BEGIN SELECT c.candidate_id AS student_id FROM candidates c WHERE NOT EXISTS ( SELECT 1 FROM detentions d WHERE d.student_id = c.candidate_id ) ORDER BY c.candidate_id ASC; END

Expected output for your example

student_id
35
103

Why this solution works

  1. FROM candidates c selects all scholarship candidates.
  2. NOT EXISTS excludes students who have received even one detention.
  3. AS student_id gives the output column the required name.
  4. ORDER BY c.candidate_id ASC sorts student IDs in ascending order.

Important: Your editor already contains CREATE PROCEDURE solution(), BEGIN, and END. You can simply paste the following code between BEGIN and END:

sql
SELECT c.candidate_id AS student_id FROM candidates c WHERE NOT EXISTS ( SELECT 1 FROM detentions d WHERE d.student_id = c.candidate_id ) ORDER BY c.candidate_id ASC;

This is a MySQL-compatible solution that handles students with multiple detentions and candidates with no detentions.

Condividi questa Q&A