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

When a method in a subclass overrides a method in superclass, it is still possible to call the overridden method using super keyword - Hacker Rank Solution.

Java's System.out.printf function can be used to print formatted output. The purpose of this exercise is to test your understanding of formatting output using printf. To get you started, a portion of the solution is provided for you in the editor; you must format and print the input to complete the solution.