Lesson 2.3
Why SQL Strings Need Quotes
Text columns store words and codes. Literal text values must be wrapped in quotes.
String columns hold text: names, cities, states, emails, statuses, and other labels. When you compare a column to a text value, put the value in single quotes.
Without quotes, SQL thinks the value is a column name or keyword. That is why state = PA is different from state = 'PA'.
Pattern
select text_column, another_column
from table_name
where text_column = 'exact text value'
order by text_columnSchema · Garden ShopTable · suppliers4 columns · 6 rows
Table · suppliers
4 columns · 6 rowsOne row per supplier. Some suppliers have no contact email.
supplier_id intsupplier_name textcontact_email textstate text
Your task
Fix the query so it returns the supplier name andstate for suppliers in PA, sorted by supplier name.
SQL Workbench
⌘↵ to run·
Expected answer
- Columns: supplier_name, state.
- Rows: 2 Pennsylvania suppliers.
- The suppliers should be Ironwood Tools and RootWorks Supply.
Related
Lesson
Why SQL Data Types Matter
See why text, numbers, dates, and booleans behave differently.
Lesson
Numbers and Calculations in SQL
Compare, sort, and calculate with numeric values.
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.