BondinBondin

SQLite Tutorial #01 - Read Data with SELECT

A practical, step-by-step guide for learning SQLite for Complete Beginners.

Aditya MadhokAditya Madhok3 min read
SQLite Tutorial #01 - Read Data with SELECT

The SELECT statement is the most fundamental command in SQL, and it's the first thing you'll use when working with any database. Think of your database as a giant filing cabinet filled with organized information. SELECT is how you reach into that cabinet and pull out exactly the data you need. Whether you're building an application, analyzing data, or just exploring a new database, SELECT is where everything begins. It's the bread and butter of working with databases, and you'll probably write more SELECT statements than any other type of query.


One of the most important things to understand about SELECT is that it's completely read-only. It will never modify your data in any way. You could run a SELECT query a million times, and your data would stay exactly the same. This makes it safe to use for exploration and analysis. You can experiment freely without worrying about accidentally changing anything. Think of it as looking through a window - you can see everything inside, but you can't touch it.


Let's start with the simplest possible example. The asterisk (*) symbol on your keyboard is a wildcard that means "all columns." When you write SELECT * FROM table_name, you're telling the database to return every column for every row in that table. This is the fastest way to explore a new table and understand what data it contains. You'll see all the column names, the types of data stored, and a sample of the actual values.


```

-- Select all columns from the employees table

SELECT * FROM employees;


-- Select specific columns only

SELECT name, salary, department FROM employees;


-- Select with an expression (no FROM clause needed)

SELECT 1 + 1;

```


When you know exactly what columns you need, it's better to specify them by name instead of using the asterisk. This is more efficient because the database doesn't have to read columns you don't need. It also makes your queries more readable and self-documenting. Anyone reading your code immediately knows which data you're working with. For example, if you only need employee names and salaries, write SELECT name, salary FROM employees instead of SELECT * FROM employees.


Here's something interesting - you can actually SELECT without a FROM clause in SQLite. Try SELECT 1 + 1 and SQLite acts like a calculator, returning 2. You can also try SELECT datetime('now') to get the current date and time. These are handy for quick tests, but in real-world work, you're almost always selecting from a table. The SELECT statement is incredibly versatile, and as you learn more SQL, you'll discover all the ways you can use it to retrieve exactly the data you need.


Tips:

- Use * sparingly in production - specify only the columns you need

- SELECT is read-only and doesn't modify data

- Always end statements with a semicolon

- When exploring a new database, start with SELECT * FROM table_name