Build project-scoped issue display keys from global ID and IID

Quick Overview

Write a SQL query that joins issues to their projects and builds a readable display key such as Alpha-1 from the project name and the per-project issue number. It tests joins, concatenating text with integers, and ordering on a composite unique key.

Build project-scoped issue display keys from global ID and IID

Company: GitLab

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Each issue in a project tracker has two identifiers. The global `id` is the primary key across all projects. The `iid` is scoped to a project: numbering starts at 1 in every project, so two different projects can each have an issue with `iid = 1`. Users see the project-scoped form, such as `Alpha-1`. Write a query that returns every issue with its `id`, `project_id`, `iid`, `project_name`, `title`, and a `display_key` built as the project name, a hyphen, and the `iid` (for example `Alpha-1`). Order the result by `project_id`, then `iid`, both ascending. ```hint Building the key `iid` is an integer and `name` is text. Check how your query turns the number into part of a string, and what the concatenation operator you pick does in your SQL dialect. ``` ### Input Table(s) `projects` | Column | Type | Meaning | |---|---|---| | id | INT | Project id. Primary key. | | name | VARCHAR(100) | Project name. NOT NULL. | `issues` | Column | Type | Meaning | |---|---|---| | id | INT | Global issue id. Primary key. | | project_id | INT | Project the issue belongs to. NOT NULL, foreign key to `projects.id`. | | iid | INT | Issue number within its project. NOT NULL. | | title | VARCHAR(255) | Issue title. NOT NULL. | | created_at | TIMESTAMP | When the issue was created. NOT NULL. | Keys: `projects.id` and `issues.id` are primary keys. `(issues.project_id, issues.iid)` is unique. `issues.project_id` references `projects.id`. ### Output Contract - Columns, in this order: `id`, `project_id`, `iid`, `project_name`, `title`, `display_key`. - `id`, `project_id`, `iid` and `title` come from `issues`. `project_name` is `projects.name`. - `display_key` is text: the project name exactly as stored, then `-`, then `iid` written as a plain decimal number with no padding (`Alpha-1`, `Alpha-12`). - One row per issue. - Order by `project_id` ascending, then `iid` ascending. That pair is unique, so the order is fully determined. - No rounding applies. ### Example `projects` | id | name | |---|---| | 1 | Alpha | | 2 | Beta | | 3 | Gamma | `issues` | id | project_id | iid | title | created_at | |---|---|---|---|---| | 101 | 2 | 1 | Login page returns 500 | 2024-03-01 09:00:00 | | 102 | 1 | 1 | Add CSV export | 2024-03-01 10:15:00 | | 103 | 1 | 2 | Fix typo in README | 2024-03-02 08:30:00 | | 104 | 2 | 2 | Rate limit webhook calls | 2024-03-03 14:00:00 | Expected output: | id | project_id | iid | project_name | title | display_key | |---|---|---|---|---|---| | 102 | 1 | 1 | Alpha | Add CSV export | Alpha-1 | | 103 | 1 | 2 | Alpha | Fix typo in README | Alpha-2 | | 101 | 2 | 1 | Beta | Login page returns 500 | Beta-1 | | 104 | 2 | 2 | Beta | Rate limit webhook calls | Beta-2 | Issue 101 has the smallest global `id` but comes third, because the order is by project and then by project-scoped number. Gamma has no issues, so it produces no row. ### Constraints and Clarifications - `issues` has at most 10,000 rows and `projects` at most 1,000. - `iid` values are positive integers starting from 1 within each project. - `(project_id, iid)` is unique, so no two rows tie on the sort key. - Every issue belongs to an existing project, and no column in either table is NULL. - Projects without issues do not appear in the output.

Overview: Write a SQL query that joins issues to their projects and builds a readable display key such as Alpha-1 from the project name and the per-project issue number. It tests joins, concatenating text with integers, and ordering on a composite unique key.

GitLab logo
GitLab
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Each issue in a project tracker has two identifiers. The global id is the primary key across all projects. The iid is scoped to a project: numbering starts at 1 in every project, so two different projects can each have an issue with iid = 1. Users see the project-scoped form, such as Alpha-1.

Write a query that returns every issue with its id, project_id, iid, project_name, title, and a display_key built as the project name, a hyphen, and the iid (for example Alpha-1). Order the result by project_id, then iid, both ascending.

Input Table(s)

projects

ColumnTypeMeaning
idINTProject id. Primary key.
nameVARCHAR(100)Project name. NOT NULL.

issues

ColumnTypeMeaning
idINTGlobal issue id. Primary key.
project_idINTProject the issue belongs to. NOT NULL, foreign key to projects.id.
iidINTIssue number within its project. NOT NULL.
titleVARCHAR(255)Issue title. NOT NULL.
created_atTIMESTAMPWhen the issue was created. NOT NULL.

Keys: projects.id and issues.id are primary keys. (issues.project_id, issues.iid) is unique. issues.project_id references projects.id.

Output Contract

  • Columns, in this order: id , project_id , iid , project_name , title , display_key .
  • id , project_id , iid and title come from issues . project_name is projects.name .
  • display_key is text: the project name exactly as stored, then - , then iid written as a plain decimal number with no padding ( Alpha-1 , Alpha-12 ).
  • One row per issue.
  • Order by project_id ascending, then iid ascending. That pair is unique, so the order is fully determined.
  • No rounding applies.

Example

projects

idname
1Alpha
2Beta
3Gamma

issues

idproject_idiidtitlecreated_at
10121Login page returns 5002024-03-01 09:00:00
10211Add CSV export2024-03-01 10:15:00
10312Fix typo in README2024-03-02 08:30:00
10422Rate limit webhook calls2024-03-03 14:00:00

Expected output:

idproject_idiidproject_nametitledisplay_key
10211AlphaAdd CSV exportAlpha-1
10312AlphaFix typo in READMEAlpha-2
10121BetaLogin page returns 500Beta-1
10422BetaRate limit webhook callsBeta-2

Issue 101 has the smallest global id but comes third, because the order is by project and then by project-scoped number. Gamma has no issues, so it produces no row.

Constraints and Clarifications

  • issues has at most 10,000 rows and projects at most 1,000.
  • iid values are positive integers starting from 1 within each project.
  • (project_id, iid) is unique, so no two rows tie on the sort key.
  • Every issue belongs to an existing project, and no column in either table is NULL.
  • Projects without issues do not appear in the output.