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

Erstellt am: 7. November 2026

Beantwortet mit GPT-6 Thinking von Chat01

Frage

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

Gedanke

Worked for a couple of seconds

Antwort

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.

Diesen Q&A teilen