Practical guide

SQL SELECT and WHERE: Retrieve the Rows You Need

SELECT reads data without changing it. Naming only the columns and rows you need makes queries clearer and often reduces unnecessary work.

What to do

  1. Retrieve two columns with SELECT name, city FROM customers;. Use a semicolon to mark the end of a statement in many SQL tools.
  2. Filter rows with SELECT name FROM customers WHERE city = 'Vijayapura';. Text values use single quotes in standard SQL.
  3. Combine conditions with AND or OR and use parentheses when mixing them, so the intended logic is explicit.
  4. Start with SELECT and WHERE on a small result set; verify the results before using a similar condition in any data-changing statement.

Checks and limitations

  • Table and column names, string comparison rules, and quoting for identifiers vary between database systems.
  • Avoid selecting sensitive columns you do not need, especially when working with production data.