Show column value twice in MySQL Select?

MySQLMySQLi Database

You can use concat(). Let us first create a table −

mysql> create table DemoTable
(
   Value int
);
Query OK, 0 rows affected (0.73 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(100);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values(200);
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable values(100);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values(200);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values(200);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values(100);
Query OK, 1 row affected (0.30 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-------+
| Value |
+-------+
|   100 |
|   200 |
|   100 |
|   200 |
|   200 |
|   100 |
+-------+
6 rows in set (0.00 sec)

Following is the query to display column value twice in MySQL −

mysql> select concat(Value,'~',Value) from DemoTable group by Value;

This will produce the following output −

+-------------------------+
| concat(Value,'~',Value) |
+-------------------------+
|                 100~100 |
|                 200~200 |
+-------------------------+
2 rows in set (0.00 sec)
raja
Published on 30-Sep-2019 06:53:24
Advertisements