Databases Reporting with SQL Working with Text Concatenating Text

SQL Reporting ecommerce challenge; concatenate


Having issues with syntax here and the spacing I believe.

The challenge is

  • In an ecommerce database there's a addresses table. There is an id, nickname, street, city, state, zip, country and user_id columns.
  • Concatenate the street, city, state, zip and country in the following format. Street, City, State Zip. Country e.g. 34 NE 12 st, Portland, OR 97129. USA
  • Alias the concatenated string as address

Answer: I've come up with the following. There's a space after the commas, minutes the . for the zip but I added another space inbetween it and Country. Thoughts?

select Street || ", " || City || ", " || State || " " || Zip || "." || " " || Country || as address from addresses;

1 Answer

Steven Parker
Steven Parker
170,221 Points

You have an extra concatenation operator after "Country".

Optionally, you could combine the period and space into one string as you did with the comma/space strings.