MYSQLにて文字列を連結する為にCONCATを利用

    NULLを含んだ連結はNULLになります。


mysql> SELECT CONCAT(NULL,'文字列連結');
+--------------------------------+
| CONCAT(NULL,'文字列連結') |
+--------------------------------+
| NULL |
+--------------------------------+
1 row in set (0.00 sec)

mysql> SELECT CONCAT(NULL,'文字列連結');
+--------------------------------+
| CONCAT(NULL,'文字列連結') |
+--------------------------------+
| NULL |
+--------------------------------+
1 row in set (0.00 sec)

mysql>

letter

    数値も文字列に変換されて連結される。


mysql> select concat('12345','678910');
+--------------------------+
| concat('12345','678910') |
+--------------------------+
| 12345678910 |
+--------------------------+
1 row in set (0.00 sec)

mysql> select concat(12345,678910);
+----------------------+
| concat(12345,678910) |
+----------------------+
| 12345678910 |
+----------------------+
1 row in set (0.00 sec)

mysql>

number

    テーブルからデータをSELECTして連結


mysql> select company_id,company_name from STUDY where company_id =50;
+------------+--------------+
| company_id | company_name |
+------------+--------------+
| 50 | yahoo |
+------------+--------------+
1 row in set (0.00 sec)

mysql> select concat(company_id,company_name) from STUDY where company_id = 50;
+---------------------------------+
| concat(company_id,company_name) |
+---------------------------------+
| 50yahoo |
+---------------------------------+
1 row in set (0.00 sec)

mysql>

table1

Comments are closed.

Post Navigation