CONCAT() – Combine Strings Together in SQL

🔧 Quick Syntax

SELECT CONCAT(value1, value2, ...)
FROM table_name;

This tells SQL:

“Take these columns or strings and glue them together into one.”

🧾 Here’s the Table You’re Working With

Your table is called customers:

id first_name last_name city
1FennRaskFogtown
2MiloKreshDustvale
3SoraDuneCloudhill
4ToviGlintWindmere
5LexaVohnFogtown

✅ Suppose You Want to Show Full Names

SELECT CONCAT(first_name, ' ', last_name) AS full_name
FROM customers;

💡 Output:

Fenn Rask
Milo Kresh
Sora Dune
Tovi Glint
Lexa Vohn

SQL combined first_name and last_name with a space in between — clean and readable.


✅ Suppose You Want to Add a City Label

SELECT CONCAT(first_name, ' from ', city) AS intro
FROM customers;

💡 Output:

Fenn from Fogtown
Milo from Dustvale
Sora from Cloudhill
Tovi from Windmere
Lexa from Fogtown

SQL lets you mix columns and custom text — great for intros or personalized views.


✅ Suppose You Want to Generate Custom IDs

SELECT CONCAT('cust_', id) AS customer_id
FROM customers;

💡 Output:

cust_1
cust_2
cust_3
cust_4
cust_5

You’re generating a custom string like cust_3 using a static prefix and the id. Super useful for codes, labels, and display formatting.


🧃 Recap – What You Learned

  • CONCAT() joins columns and/or strings into one
  • You can add spaces, labels, text, or symbols as needed
  • Great for full names, custom codes, messages, or formatted output
  • Use AS to name the new column

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top