Hackerrank – SQL – Select By ID

Repo https://github.com/mrpunkdasilva/hackerrank/blob/main/sql/basic/select-by-id/README.md

Problem Description

Query all columns for a city in the CITY table with the ID 1661.

Input Format

The CITY table is described as follo…


This content originally appeared on DEV Community and was authored by Mr Punk da Silva

Repo https://github.com/mrpunkdasilva/hackerrank/blob/main/sql/basic/select-by-id/README.md

Problem Description

Query all columns for a city in the CITY table with the ID 1661.

Input Format

The CITY table is described as follows:

Field Type
ID NUMBER
NAME VARCHAR2(17)
COUNTRYCODE VARCHAR2(3)
DISTRICT VARCHAR2(20)
POPULATION NUMBER

Solution Approach

Use a SELECT statement with the asterisk (*) wildcard to retrieve all columns from the CITY table, and apply a WHERE clause to filter for the specific ID.

Step-by-Step Explanation

  1. Start with the SELECT statement to retrieve all columns:
   SELECT *
  1. Specify the table to query from:
   FROM CITY
  1. Add the WHERE clause to filter by ID:
   WHERE ID = 1661
  1. The final query:
   SELECT
   *
   FROM
   CITY
   WHERE
   ID = 1661;

Expected Output

The query will return all columns (ID, NAME, COUNTRYCODE, DISTRICT, POPULATION) for the city with ID 1661.


This content originally appeared on DEV Community and was authored by Mr Punk da Silva


Print Share Comment Cite Upload Translate Updates
APA

Mr Punk da Silva | Sciencx (2025-07-21T23:32:21+00:00) Hackerrank – SQL – Select By ID. Retrieved from https://www.scien.cx/2025/07/21/hackerrank-sql-select-by-id/

MLA
" » Hackerrank – SQL – Select By ID." Mr Punk da Silva | Sciencx - Monday July 21, 2025, https://www.scien.cx/2025/07/21/hackerrank-sql-select-by-id/
HARVARD
Mr Punk da Silva | Sciencx Monday July 21, 2025 » Hackerrank – SQL – Select By ID., viewed ,<https://www.scien.cx/2025/07/21/hackerrank-sql-select-by-id/>
VANCOUVER
Mr Punk da Silva | Sciencx - » Hackerrank – SQL – Select By ID. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/21/hackerrank-sql-select-by-id/
CHICAGO
" » Hackerrank – SQL – Select By ID." Mr Punk da Silva | Sciencx - Accessed . https://www.scien.cx/2025/07/21/hackerrank-sql-select-by-id/
IEEE
" » Hackerrank – SQL – Select By ID." Mr Punk da Silva | Sciencx [Online]. Available: https://www.scien.cx/2025/07/21/hackerrank-sql-select-by-id/. [Accessed: ]
rf:citation
» Hackerrank – SQL – Select By ID | Mr Punk da Silva | Sciencx | https://www.scien.cx/2025/07/21/hackerrank-sql-select-by-id/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.