Databases Reporting with SQL Working with Text Single vs Double Quotes

hamsternation
hamsternation
18,259 Points

I don't get this. Are there any documentation that helps explain this further?

I don't understand the difference between string literals and column aliases, and why those two has to be identified using different type of quotes? Are there other cases where different quotes has to be used?

3 Answers

Steven Parker
Steven Parker
163,092 Points

For the most part, you will use single quotes with SQL. Double quotes are rarely needed, and generally only when a column name (either an actual column or an alias) contains some unusual character like a space or symbol. The key to remember is single is for string, and double is for identifier.

The SQLite database used in the courses is more flexible that most, as it will allow the use of single or double quotes for both identifiers and strings. But it's good to get in the habit of using them in the "official" way so you can work with other databases easily later.

Steven Parker
Steven Parker
163,092 Points

hamsternation — Did this answer your question? You can mark a question solved by choosing a "best answer".
And happy coding!

kevin hudson
PRO
kevin hudson
Pro Student 9,098 Points

So in simple terms - if you need to concatenate a string with a column then use single quotes - if you are alias a column then use double quote marks.