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
Bob Smith
6,711 PointsString Function SQL
Select the "first_name" followed by the username in parentheses and alias it as "display_name". For example "Andrew (chalkers)". There's a space between the end of the first_name and username in parentheses.
Why is the code below not working?! Thank you.
SELECT CONCAT(first_name," ",(username)) AS display_name FROM users;
2 Answers
Mike DeHart
9,088 PointsWhat output are you getting? Any what SQL version are you using? The annoying thing about SQL are the syntax differences between versions. I'm not very knowledgeable about mySQL so someone may have better input. In T-SQL that would be 'select first_name +' '+'('+username+')' as display_name from users If the 'username' column doesn't have parenthesis around it that could be the issue as it won't recognize the difference between 'username' and '(username)'
Again, I use a different version of SQL thought that doesn't have a concat function, but just my 2 cents
Andrew Shook
31,709 PointsYour code isn't working because you have username wrapped in parentheses, you need to add the parentheses as a string.
SELECT CONCAT(first_name," (",username,")") AS display_name FROM users.
Bob Smith
6,711 PointsSQL version shouldn't matter.. working in the treehouse console.
Oh right... have to take note of that a I didn't know it could be written like that. Thank you.
Andrew Shook
31,709 PointsJosh, I'm relatively certain that Mike meant type of SQL and not version, and there can be big differences between different types of sql.
Mike DeHart
9,088 PointsThats right Andrew, thanks for the correction. It might not matter just doing treehouse examples, but in real-world situations, especially working with proprietary databases, the many 'flavors' of SQL make cross-platform programming a big headache!
Bob Smith
6,711 PointsCool thanks guys, wasn't quite aware of this. Appreciate all of the feedback.