Skip to main content

Selecting Specific Columns

Choosing only needed columns improves readability and often reduces work for your application.

Core Concepts

flowchart TD
A[Table with many columns] --> B[Pick required columns]
B --> C[Smaller result set]
Query styleExampleOutcome
All columnsSELECT * FROM customers;Full row shape
Specific columnsSELECT name, email FROM customers;Focused result

Code Examples

-- Setup sample table.
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL,
city TEXT
);

INSERT INTO customers (name, email, city)
VALUES ('Priya', 'priya@example.com', 'Delhi');
Expected output
Table created and one row inserted.
-- Select only two columns.
SELECT name, email
FROM customers;
nameemail
Priyapriya@example.com

SQLite-Specific Nuances

SQLite Nuance

SQLite returns result columns in the exact order you list in SELECT.

Common Pitfalls / Best Practices

Pitfall

Using SELECT * in APIs and then depending on implicit column order.

Best Practice

List columns intentionally and keep ordering stable for downstream code.

Quick Challenge

Return only city from customers.

View Solution
SELECT city
FROM customers;
city
Delhi