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 Reporting with SQL Working with Text Creating Excerpts From Text

Concatenate empty data

Hi,

How do I write my query if I'm using concatenation with two columns, say for instance, first_name and last_name, and there are empty cells for some last_name?

Thanks

Are you talking about empty or null? If null the default behavior is to return null when concatenating values (depending on the data engine and settings used).

I just tried in the playground and found this to be the case. Open the playground for the video and run the following

SELECT typeof(first_name || last_name) AS myname FROM customers WHERE last_name IS NULL;
UPDATE customers SET last_name = '' WHERE last_name IS NULL; 
SELECT first_name || last_name AS myname FROM customers WHERE last_name = '';

The first select returns null for the concatenated fields

The update statement updates null last_names to empty

The second select returns the first name and an empty string for the concatenated fields

1 Answer

They'll just be empty unless you want to filter or replace the empty value somehow

Hi Thanks for your response. When I tried it came back with both empty, even though there was a first name.