Learn SQL
SQL Data Types Explained: Text, Numbers, Dates, and Better Questions
Data types are the reason SQL knows the difference between a name, a salary, and a hire date — and that difference shapes every query you write.
On This Page
Data types give values meaning
A table tells you where data lives. Data types tell you what the values mean. That distinction sounds small, but it is one of the reasons SQL can do more than display rows on a screen.
In SQL for Files, you can practice this idea without setting up a database server. Load sample lesson data or bring your own CSV, JSON, or Parquet file into the browser, inspect the inferred columns, and run SQL locally with DuckDB WASM.
The three beginner types you will see everywhere
Most beginner SQL examples start with three everyday categories: text, numbers, and dates. They look obvious in a small table, but SQL treats them differently because they support different kinds of questions.
- Text stores words and characters, such as employee names, departments, product codes, or regions.
- Numbers store quantities and measures, such as salaries, prices, counts, and percentages.
- Dates store calendar or time values, such as hire dates, order dates, timestamps, and event times.
id INTEGER
name VARCHAR
department VARCHAR
salary DECIMAL
hire_date DATEDifferent types unlock different questions
A salary is not just characters on a screen. Because SQL understands it as a number, you can calculate a minimum, maximum, average, or total. A hire date is not just a label. Because SQL understands it as a date, you can sort chronologically or filter people hired after a certain day.
SELECT
AVG(salary) AS average_salary,
MIN(hire_date) AS earliest_hire_date
FROM employees;Text has its own strengths. You can search for names, group by departments, match patterns, and label results. The important part is not that one type is better than another. The important part is that SQL chooses behavior based on type.
When a value has the wrong type, queries get weird
A common beginner surprise is that a value can look right but behave wrong. The value 2026 might be a number, part of a date, or text inside an ID. SQL needs the type to know whether it should add it, sort it alphabetically, compare it as a date, or preserve it exactly as written.
Practical habit
When you import a file, inspect the detected schema before writing a serious query. A column that looks numeric or date-like may still be stored as text depending on the file contents.
Practice data types in SQL for Files
The second Learn SQL lesson introduces data types using a simple employee table. It shows why names, departments, salaries, and hire dates are not interchangeable, even when they all sit side by side in one row.
- Open the related Data Types lesson below.
- Notice which columns are text, numbers, and dates.
- Then continue toward SELECT queries, where those types start to affect real results.
Continue in the editor
Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.
Open editorRelated Learn SQL lessons
Related guides
What Is a Database Table? Rows, Columns, and the Mental Model Behind SQL
Before SQL feels natural, you need one simple mental model: tables are structured collections of records with predictable columns.
SQL NULL Explained: How Missing Values Work and Why They Matter
NULL is SQL's way of saying a value is missing or unknown — and it behaves differently from almost every other value beginners expect.
How to Query CSV Files with SQL in Your Browser
Use SQL for Files as a local CSV analysis workspace: add a file, inspect the generated table, write SQL, and export the rows you need.