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

KRIS NIKOLAISEN
KRIS NIKOLAISEN
Pro Student 42,606 Points

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

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 42,606 Points

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.