- This topic is empty.
-
AuthorPosts
-
February 13, 2026 at 1:06 am #6043
❓ Q1: Why did I get this error in SQLite?
Parse error: near “School”: syntax error
When I ran this query:
SELECT name, city FROM schools WHERE type = Public School AND city = Massachusetts;✅ Answer:
Because text values must be written inside quotes in SQL.
Without quotes, SQLite treatsPublicandSchoolas column names, which causes a syntax error.
❓ Q2: What is the correct way to write this query?
✅ Answer:
Use single quotes
' 'for text values:SELECT name, city FROM schools WHERE type = 'Public School' AND city = 'Massachusetts';This tells SQLite that
"Public School"and"Massachusetts"are strings, not column names.
❓ Q3: Why are quotes mandatory for text in SQL?
✅ Answer:
SQL has different rules for different data types:
Data Type Example Needs Quotes? Number 25 ❌ No Text School ✅ Yes Example:
age = 25 -- OK city = 'Boston' -- OKWithout quotes, SQL gets confused.
❓ Q4: Should I use single quotes or double quotes?
✅ Answer:
Always prefer single quotes
' 'for text.✔ Correct:
city = 'Delhi'❌ Avoid:
city = "Delhi"Because
" "is usually meant for column names in SQL.
❓ Q5: How can I check what values exist in a column?
✅ Answer:
If you are unsure about exact values, run:
SELECT DISTINCT type FROM schools;or
SELECT DISTINCT city FROM schools;This shows all available options so you can match them correctly.
❓ Q6: What if my query still gives no results?
✅ Answer:
Check for:
1️⃣ Case Sensitivity
Some databases treat text as case-sensitive.
Try:
SELECT name, city FROM schools WHERE LOWER(type) = 'public school' AND LOWER(city) = 'massachusetts';2️⃣ Extra Spaces
Sometimes data contains spaces:
SELECT name, city FROM schools WHERE TRIM(type) = 'Public School';
❓ Q7: What is the main lesson from this error?
✅ Answer:
👉 Always wrap text values in single quotes when writing SQL queries.
✔ Rule to remember:
Text → ' ' Numbers → no quotes
✅ Final Correct Query (Reference)
SELECT name, city FROM schools WHERE type = 'Public School' AND city = 'Massachusetts';
-
AuthorPosts
- You must be logged in to reply to this topic.

