Hackerrank - SQL - Select By ID
Mr Punk da Silva

Mr Punk da Silva @mrpunkdasilva

About: I'm a Brazilian Software Engineer passionate about creating elegant solutions for complex problems. I specialize in full-stack development with a focus on clean code, solid architecture, and exception

Location:
In my mind
Joined:
Jul 19, 2023

Hackerrank - SQL - Select By ID

Publish Date: Jul 21
1 0

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 *
Enter fullscreen mode Exit fullscreen mode
  1. Specify the table to query from:
   FROM CITY
Enter fullscreen mode Exit fullscreen mode
  1. Add the WHERE clause to filter by ID:
   WHERE ID = 1661
Enter fullscreen mode Exit fullscreen mode
  1. The final query:
   SELECT
   *
   FROM
   CITY
   WHERE
   ID = 1661;
Enter fullscreen mode Exit fullscreen mode

Expected Output

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

Comments 0 total

    Add comment