Querying a Table
Learn how to view the database with an SQL query.
Step 1: Start with a question
Let’s imagine you’re exploring a table named employees. You don’t know what’s in it yet.
Ask yourself:
What data do I actually want to see first?
Maybe something simple like:
Show me all the employee records.
Now, don’t write SQL yet; ask AI to translate that question.
Prompt: Write a SQL query that displays all employees from the employees table.
Step 2: Run and observe
AI will probably return:
You should see something like:
ID | First Name | Last Name | Department | Salary |
1 | Alice | Kim | Marketing | 75,000 |
2 | Raj | Patel | Engineering | 95,000 |
3 | Maria | Lopez | Finance | 88,000 |
4 | David | Nguyen | Engineering | 102,000 |
5 | Sofia | Rossi | Design | 72,000 |
6 | James | Olsen | Sales | 68,000 |
7 | Lina | Chen | HR | 64,000 |
8 | Omar | Hassan | Operations | 85,000 |
9 | Ethan | Brown | Support | 58,000 |
10 | Isabella | Garcia | Engineering | 97,000 |
Take a moment to visualize your data structure:
Each row represents a single record, in this case, an employee.
Each column represents a specific piece of information about that record.
When you write:
SELECT *
You’re telling SQL: Show me every column in the table.
Step 3: Narrow the focus
Seeing everything is messy. Let’s make our question sharper: Show me each employee’s first name and department.
Use the AI again.
Prompt: Write a SQL query that shows only the employee’s first name and department from the employees table.
AI might give you:
Run it. You’ll now see a cleaner table with fewer columns and the same rows.
Ask yourself:
Which question gives you a clearer picture?
Why might analysts rarely use
*in real life?
Step 4: Reflect and interpret
Let’s think together:
SELECT: Which columns do I want?FROM: Which table has them?*: All columns (not always useful).
A good SQL query isn’t just syntax; it’s a clear question. Every line you write should match the question you’re asking.
Step 5: Your turn to tweak
Now you’ll make a small edit yourself. No AI this time, type directly in the SQL widget.
Challenge: Change the query so it shows
first_name,last_name, andsalaryof allemployees.
Did you get a new table with just those three columns?
That’s your first hand-written SQL query. Small tweak, big step, you’ve moved from AI-generated to AI-assisted.
Quick recap
SQL Keyword | What It Means | Example |
| Pick which columns to show |
|
| Tell SQL which table to use |
|
| Shortcut for “all columns” |
|
Practice prompt ideas
Use the AI Prompt Widget to try your own:
Show me the names and salaries of employees.
Show only the employee id and department.
List all columns again using SELECT *.
Then tweak one of them yourself to add or remove a column.
Reflect before moving on
Ask yourself:
How did my question in plain English become SQL?
Why is narrowing columns helpful?
What would I ask next to start learning about the types of data this table holds?
You’ve just completed Lesson 1. You can now ask AI a data question in natural language, read and run the SQL it produces, and manually edit it to explore new columns.