List each distinct payment method in alphabetical order

Quick Overview

Write a SQL query that returns each payment method used in a payments table exactly once, sorted alphabetically. It tests removing duplicate values from a single column and returning rows in a guaranteed order.

List each distinct payment method in alphabetical order

Company: Cloudflare

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

The `payments` table records one row per payment a customer makes. Return a single column `payment_method` containing each distinct payment method in `payments`, ordered alphabetically. ### Input Table(s) `payments` | Column | Type | Meaning | |---|---|---| | payment_id | INT | Payment id | | customer_id | INT | Customer who made the payment, NOT NULL | | amount | DECIMAL(10,2) | Payment amount, NOT NULL | | payment_method | VARCHAR(50) | Method used for the payment, NOT NULL | | payment_date | DATE | Date of the payment, NOT NULL | Primary key: `payment_id`. ### Output Contract | Column | Type | Meaning | |---|---|---| | payment_method | VARCHAR(50) | One distinct payment method | Return one row per distinct `payment_method`, ordered by `payment_method` ascending. The values are unique in the output, so the order is fully determined. There is nothing to round. ### Example `payments` | payment_id | customer_id | amount | payment_method | payment_date | |---|---|---|---|---| | 1 | 101 | 25.00 | credit_card | 2024-01-05 | | 2 | 102 | 40.50 | paypal | 2024-01-05 | | 3 | 101 | 12.00 | credit_card | 2024-01-07 | | 4 | 103 | 99.99 | bank_transfer | 2024-01-08 | | 5 | 102 | 15.00 | paypal | 2024-01-09 | Expected result | payment_method | |---| | bank_transfer | | credit_card | | paypal | Five payments use three methods. `credit_card` and `paypal` each appear twice but are listed once, and the three values are sorted alphabetically. ### Constraints and Clarifications - `payments` contains at least 1 row. - `payment_method` is never NULL and is 1 to 50 characters long. - `1 <= payment_id <= 10000`, so the table has at most 10,000 rows. - Values are compared exactly as stored. Two values that differ only in capitalization or spacing count as two different methods. - The other columns do not affect the result. A method used once and a method used a thousand times each appear once.

Overview: Write a SQL query that returns each payment method used in a payments table exactly once, sorted alphabetically. It tests removing duplicate values from a single column and returning rows in a guaranteed order.

Cloudflare logo
Cloudflare
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

The payments table records one row per payment a customer makes. Return a single column payment_method containing each distinct payment method in payments, ordered alphabetically.

Input Table(s)

payments

ColumnTypeMeaning
payment_idINTPayment id
customer_idINTCustomer who made the payment, NOT NULL
amountDECIMAL(10,2)Payment amount, NOT NULL
payment_methodVARCHAR(50)Method used for the payment, NOT NULL
payment_dateDATEDate of the payment, NOT NULL

Primary key: payment_id.

Output Contract

ColumnTypeMeaning
payment_methodVARCHAR(50)One distinct payment method

Return one row per distinct payment_method, ordered by payment_method ascending. The values are unique in the output, so the order is fully determined. There is nothing to round.

Example

payments

payment_idcustomer_idamountpayment_methodpayment_date
110125.00credit_card2024-01-05
210240.50paypal2024-01-05
310112.00credit_card2024-01-07
410399.99bank_transfer2024-01-08
510215.00paypal2024-01-09

Expected result

payment_method
bank_transfer
credit_card
paypal

Five payments use three methods. credit_card and paypal each appear twice but are listed once, and the three values are sorted alphabetically.

Constraints and Clarifications

  • payments contains at least 1 row.
  • payment_method is never NULL and is 1 to 50 characters long.
  • 1 <= payment_id <= 10000 , so the table has at most 10,000 rows.
  • Values are compared exactly as stored. Two values that differ only in capitalization or spacing count as two different methods.
  • The other columns do not affect the result. A method used once and a method used a thousand times each appear once.