Write an SQL query to retrieve the supplier number and supplier names from the supplier table, where the supplier name starts with the letter ‘R’.

Write an SQL query to retrieve the supplier number and supplier names from the supplier table, where the supplier name starts with the letter ‘R’.

The Correct Answer and Explanation is:

✅ SQL Query:

SELECT supplier_number, supplier_name
FROM supplier
WHERE supplier_name LIKE 'R%';

📝 Explanation (300+ Words):

This SQL query is designed to retrieve specific columns from a table called supplier, based on a filter condition involving the supplier_name column.

🔍 Breakdown of the Query:

  1. SELECT supplier_number, supplier_name
    • The SELECT statement is used to specify which columns you want to retrieve from the table.
    • In this case, we are interested in two columns:
      • supplier_number: Likely a unique identifier for each supplier.
      • supplier_name: The name of the supplier.
  2. FROM supplier
    • This clause tells the database which table to pull the data from.
    • Here, it is the supplier table, which stores information about suppliers.
  3. WHERE supplier_name LIKE ‘R%’
    • The WHERE clause is used to filter records based on a condition.
    • supplier_name LIKE 'R%':
      • The LIKE operator is used for pattern matching in SQL.
      • 'R%' means any string that starts with the letter ‘R’, followed by zero or more characters.
      • % is a wildcard that represents any sequence of characters, including no character.
      • So, this condition returns supplier names such as:
        • 'Ravi Supplies'
        • 'Redline Corp'
        • 'Royal Traders'

🧠 Why Use LIKE Instead of =?

Using = would match the name exactly. For example:

WHERE supplier_name = 'Ravi'

…would only return results where the supplier name is exactly 'Ravi'.

In contrast, LIKE 'R%' is more flexible and retrieves all names that begin with ‘R’, regardless of what follows.

✅ Summary:

This query is useful when you need to:

  • Retrieve specific data (supplier_number and supplier_name)
  • Filter results based on a textual pattern
  • Match supplier names starting with a particular letter (here, 'R')

It demonstrates a fundamental concept in SQL: pattern-based filtering using the LIKE operator.

Scroll to Top