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

The CITY table is described as follows:

THEORY:

What is a SELECT Statement?

The SELECT statement is used to retrieve data from one or more tables in a database. It is the most commonly used command in SQL (Structured Query Language).

Types of SELECT Queries

  1. Simple SELECT

    SELECT * FROM customers;
  2. SELECT with WHERE

    SELECT name FROM customers WHERE country = 'USA';
  3. SELECT with Aggregates

    SELECT COUNT(*) FROM orders;
  4. SELECT with JOIN

    SELECT orders.id, customers.name FROM orders JOIN customers ON orders.customer_id = customers.id;
  5. SELECT with Subquery

    SELECT name FROM customers WHERE id IN (SELECT customer_id FROM orders WHERE amount > 1000);

🔹 Important Notes

  • SQL is not case-sensitive, but common practice is to write keywords in UPPERCASE.

  • You can alias columns and tables for readability:

    SELECT name AS customer_name FROM customers;


SOLUTION:

SELECT * FROM CITY WHERE ID='1661';

Popular posts from this blog

In this problem, you will practice your knowledge on interfaces - Hacker Rank Solution.