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
- Start with the SELECT statement to retrieve all columns:
SELECT *
- Specify the table to query from:
FROM CITY
- Add the WHERE clause to filter by ID:
WHERE ID = 1661
- 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.