Lesson 2.1
Why SQL Data Types Matter
SQL uses column types to decide how values compare, sort, and calculate.
Every column has a type. A column might hold text, numbers, dates, booleans, or missing values. SQL uses those types when it sorts, compares, filters, and calculates.
The difference matters quickly. Sorting product names alphabetically is different from sorting product prices numerically.
Pattern
select column_one, number_column
from table_name
order by number_column descSchema · Garden ShopTable · products9 columns · 24 rows
Table · products
9 columns · 24 rowsOne row per product, with price, cost, and inventory levels.
product_id intproduct_name textcategory_id intsupplier_id intprice decimalcost decimalquantity_on_hand intreorder_level intdiscontinued bool
Your task
Show each product's product name and price, sorted from the highest price to the lowest. Keep only the first 5 rows.
SQL Workbench
⌘↵ to run·
Expected answer
- Columns: product_name, price.
- Rows: 5 products.
- The first row should be Fiddle-Leaf Fig at 32.00.
Related
Lesson
Numbers and Calculations in SQL
Compare, sort, and calculate with numeric values.
Lesson
Why SQL Strings Need Quotes
Filter text values with string literals.
Lesson
Working with Dates and Times in SQL
Compare and sort date values chronologically.
Lesson
Booleans and Flag Columns in SQL
Use true/false columns in filters.