How to create Tab Delimited Select statement in MySQL?

MySQLMySQLi Database

To create a tab delimited select statement, you can use CONCAT() function from MySQL. Following is the syntax:

select concat(yourColumnName1,"\t",yourColumnName2) AS anyAliasName from yourTableName;

Let us first create a table:

mysql> create table DemoTable
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   FirstName varchar(20),
   LastName varchar(20)
);
Query OK, 0 rows affected (0.81 sec)

Following is the query to insert records in the table using insert command:

mysql> insert into DemoTable(FirstName,LastName) values('John','Smith');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable(FirstName,LastName) values('Carol','Taylor');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable(FirstName,LastName) values('John','Doe');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable(FirstName,LastName) values('David','Miller');
Query OK, 1 row affected (0.12 sec)

Following is the query to display records from the table using select command:

mysql> select *from DemoTable;

This will produce the following output

+----+-----------+----------+
| Id | FirstName | LastName |
+----+-----------+----------+
|  1 | John      | Smith    |
|  2 | Carol     | Taylor   |
|  3 | John      | Doe      |
|  4 | David     | Miller   |
+----+-----------+----------+
4 rows in set (0.00 sec)

Following is the query to create tab delimited select statement:

mysql> select concat(FirstName,"\t",LastName) AS Tab_Delimited_Demo from DemoTable;

This will produce the following output:

+--------------------+
| Tab_Delimited_Demo |
+--------------------+
| John Smith         |
| Carol Taylor       |
| John Doe           |    
| David Miller       |
+--------------------+
4 rows in set (0.00 sec)
raja
Published on 29-Apr-2019 11:48:07
Advertisements