BBampaa

Lessons › SQL › Chapter 1: Reading data

SQL lesson

SELECT specific columns

Selecting specific columns means naming only the fields you want back instead of pulling everything stored in a table.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Picking the columns you actually need

SELECT product_id, price FROM products

Result:

product_idprice
P2001299.99
P200249.95
P200322.5
P2004134.0
P200589.75

Step by step

  1. Start with one column. SELECT then the column name, then FROM and the table.
    SELECT product_id
    FROM products;
  2. Add a second column - separate them with a comma. Two columns come back.
    SELECT product_id, price
    FROM products;
  3. Swap the order of your columns and the result columns swap too. SQL respects the order you list.
    SELECT price, product_id
    FROM products;

Practice

Try each one in your head first, then open the answer.

1. Using the orders table, write a query to show only the order_date and category columns.
SELECT order_date, category FROM orders
2. Using the products table, write a query to show only the brand and category columns.
SELECT brand, category FROM products
3. Using the customers table, write a query to show only the signup_date and email columns.
SELECT signup_date, email FROM customers
4. Using the inventory table, write a query to show only the stock_count and warehouse columns.
SELECT stock_count, warehouse FROM inventory
5. Using the returns table, write a query to show only the return_id and refund_amount columns.
SELECT return_id, refund_amount FROM returns

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed