Skip to content
CampusEduX

List immediate lab children

Easysql
Learn the Concept: Hierarchical Model

In this relational mirror of a hierarchy, return labid and labname for labs whose departmentid is 1, ordered by labid. Do not return labs owned by another department. This is SQL representation practice, not a native IMS operation.

MySQL dialect.

sql
CREATE TABLE labs (lab_id INT PRIMARY KEY, lab_name VARCHAR(40) NOT NULL, department_id INT NOT NULL); INSERT INTO labs VALUES (20,'Networks',1),(10,'Robotics',1),(30,'Optics',2);

Required ordering: lab_id ascending

Edge cases:

  • Several labs can share one parent
  • No matching parent returns no rows
  • Repeated lab names remain separate occurrences

Related Problems

  • Count device children while retaining empty labs
    Medium · sql
    Solve Problem
  • Select one student occurrence by identity
    Easy · sql
    Solve Problem
  • Create a disposable database with explicit text defaults
    Easy · sql
    Solve Problem

Input (stdin)

Output

Run your code to see output here...