MorkaLork Development

Interesting stuff I've picked up over the years...

Mysql 13: Concatenate

2009-04-16 21:21:07 | 341 views | sql mysql table concatenate columns

CONCAT()



CONCAT() let's you concatenate columns from a record.

This will be our table 'stores'

|--------------------+--------------------+--------------------|
|store_name |store_sales |store_updates |
|____________________+____________________+____________________|
|Hanks Hardware 2500 2009-01-01 00:00:00 |
|Santos SuperStore 750 2008-12-01 00:00:00 |
|Bobs Boutique 1250 2009-01-01 00:00:00 |
|Pattyïs Pantstore 1050 2008-12-15 00:00:00 |
|Hanks Hardware 2250 2008-01-01 00:00:00 |
+--------------------------------------------------------------+



Syntax:

SELECT CONCAT(col1, col2)
FROM table


Example:


SELECT CONCAT(store_name, ' ', store_sales)
FROM stores
WHERE store_sales > 1500


|--------------------
|CONCAT(store_name, ' ', store_sales)|
|____________________
|Hanks Hardware 2500 |
|Hanks Hardware 2250 |
+----------------------+


MSSQL



The syntax for doing this in sql server is:

SELECT col1 + col2
FROM table



Article comments

Feel free to comment this article using a facebook profile.

I'm using facebook accounts for identification since even akismet couldn't handle all the spam I receive every day.