List immediate lab children
Easysql
Learn the Concept: Hierarchical ModelIn 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.
sqlCREATE 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
Example 1
Input
INSERT INTO labs VALUES (20,'Networks',1),(10,'Robotics',1),(30,'Optics',2);
Output
lab_id lab_name 10 Robotics 20 Networks
Explanation: The parent predicate selects immediate children of the requested department without inventing recursive traversal.
- Unique lab identifiers
- Each lab has one department parent
- Department references are valid fixture identities
Hint 1
Filter the immediate parent identifier
Hint 2
Preserve the lab identity
The parent predicate selects immediate children of the requested department without inventing recursive traversal.
The parent predicate selects immediate children of the requested department without inventing recursive traversal.
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Count device children while retaining empty labsMedium · sqlSolve Problem
- Select one student occurrence by identityEasy · sqlSolve Problem
- Create a disposable database with explicit text defaultsEasy · sqlSolve Problem