Selecting fields

Introduction to SQL with AI

Jasmin Ludolf

Senior Data Science Content Developer

The SELECT statement

$$

  • SELECT: what to show
  • FROM: where to look

Query:

SELECT product_name
FROM products;

Result set:

|product_name|
|------------|
|   Laptop   |
|   Desktop  |
|   Gaming   |
...
Introduction to SQL with AI

Selecting a specific field

Prompt: What are the product names?

SELECT product_name
FROM products;
|product_name|
|------------|
|   Laptop   |
|   Desktop  |
|   Gaming   |
...
  • Our AI assistant is connected to the PoweredHomes database
Introduction to SQL with AI

Selecting a specific field

Prompt: Show the product_name field from the products table

SELECT product_name
FROM products;
|product_name|
|------------|
|   Laptop   |
|   Desktop  |
|   Gaming   |
...
  • No AI knowledge requires specific prompts
Introduction to SQL with AI

Selecting all fields

Prompt: Show me everything from the products table

SELECT product_id, product_name, category, unit_price, unit_cost
FROM product;
|product_id|product_name|category |unit_price|unit_cost|
|----------|------------|---------|----------|---------|
|100       |Laptop      |Computing|649.99    |420      |
|101       |Desktop     |Computing|749.99    |480      |
|102       |Gaming      |Computing|1099.99   |800      |
|103       |Mouse       |Computing|19.99     |8        |
...
Introduction to SQL with AI

Selecting all fields

Prompt: Show me everything from the products table

SELECT *
FROM product;
|product_id|product_name|category |unit_price|unit_cost|
|----------|------------|---------|----------|---------|
|100       |Laptop      |Computing|649.99    |420      |
|101       |Desktop     |Computing|749.99    |480      |
|102       |Gaming      |Computing|1099.99   |800      |
|103       |Mouse       |Computing|19.99     |8        |
...
  • * wildcard: "select all"
  • List field names for better readability, or * for quick exploration
Introduction to SQL with AI

Selecting multiple fields

Prompt: Show the name and category for each product

SELECT product_name, category
FROM products;
|product_name|category |
|------------|---------|
|   Laptop   |Computing|
|   Desktop  |Computing|
|   Gaming   |Computing|
...
Introduction to SQL with AI

Data exploration

$$

Workflow: explore, analyze, communiate

  • Explore data to understand what's available
  • Easier to verify results and ask questions
  • Lack of understanding leads to unanswerable questions
  • AI accelerates the workflow, but human judgment is key
Introduction to SQL with AI

Let's practice!

Introduction to SQL with AI

Preparing Video For Download...