Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases SQL Basics Getting Data from a Database Categorizing Your Output with 'AS'

Noah Fields
Noah Fields
13,985 Points

Does using single vs double quotes matter in SQL here?

I managed to think ahead slightly in this video, and came up with the solution to the syntax error before Andrew Chalkley mentioned it. However, when I wrote it out I used single quotes ('First Published'), but Chalkley used double quotes ("First Published"). As far as I can tell this had no effect on the output. Should I be aware of whether I use single or double quotes? In other IDEs it's mentioned that different syntax is used, so naturally it's a case-by-case situation, but using the Treehouse Workspace should I be careful as to which types of quotes I use?

3 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya Noah! Single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally aren't used in SQL, but that can vary from database to database.

Stick to using single quotes.

That's the primary use anyways. You can use single quotes for a column alias—where you want the column name you reference in your application code to be something other than what the column is actually called in the database.

SELECT PRODUCT.id AS product_id
SELECT PRODUCT.id 'product_id'

You do have to use single quotes when the column alias includes a space character, e.g., product id, but it's not recommended practice for a column alias to be more than one word.

One comment about Ari Misha 's response above: You do have to use single quotes when the column alias includes a space character, e.g., product id, but it's not recommended practice for a column alias to be more than one word.

Both Andrew Chalkley (in the video) and Jason Anders (Moderator response to https://teamtreehouse.com/community/why-would-you-want-to-alias-a-column-name-does-this-actually-change-the-name-of-the-column-in-the-database) use two-word examples in the "Why to Use Aliases" explanations .... and, in fact, make it seem like multi-word phrases are actually a significant benefit of aliases, since aliases primarily affect what is displayed on the screen/manipulated, to make it more readable and user-friendly.

I think in general they are just stylistic preferences, like smooth. Get worked up over the perfect small picture. Miss the easy big picture. b.i.g. I think I got "it" b.i.g. ... Ghee I be t'his t'hats "it"