Search⌘ K
AI Features

Querying a Table

Explore how to use SQL queries with AI assistance to retrieve and narrow down data from tables. Understand the importance of selecting specific columns and practice editing queries to gain confidence in querying data effectively.

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.

Powered by AI
5 Prompts Remaining
Prompt AI WidgetOur tool is designed to help you to understand concepts and ask any follow up questions. Ask a question to get started.

Step 2: Run and observe

AI will probably return:

MySQL
SELECT * FROM employees;

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.

Powered by AI
3 Prompts Remaining
Prompt AI WidgetOur tool is designed to help you to understand concepts and ask any follow up questions. Ask a question to get started.

AI might give you:

MySQL
SELECT first_name, department
FROM employees;

 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, and salary of all employees.

MySQL
-- Write your query here:

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

SELECT

Pick which columns to show

SELECT name, salary

FROM

Tell SQL which table to use

FROM employees

*

Shortcut for “all columns”

SELECT *

Practice prompt ideas

Use the AI Prompt Widget to try your own:

  1. Show me the names and salaries of employees.

  2. Show only the employee id and department.

  3. 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.