

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to export specific column data in MySQL?
To export specific column data in MySQL, use OUTFILE −
select yourColumnName from yourTableName into outfile 'yourLocationOfFile’;
Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(20), StudentLastName varchar(20) ); Query OK, 0 rows affected (0.54 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable(StudentFirstName,StudentLastName) values('John','Doe'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(StudentFirstName,StudentLastName) values('David','Miller'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(StudentFirstName,StudentLastName) values('John','Smith'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(StudentFirstName,StudentLastName) values('Carol','Taylor'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(StudentFirstName,StudentLastName) values('Sam','Williams'); Query OK, 1 row affected (0.18 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+------------------+-----------------+ | StudentId | StudentFirstName | StudentLastName | +-----------+------------------+-----------------+ | 1 | John | Doe | | 2 | David | Miller | | 3 | John | Smith | | 4 | Carol | Taylor | | 5 | Sam | Williams | +-----------+------------------+-----------------+ 5 rows in set (0.00 sec)
Following is the query to export specific column data in MySQL −
mysql> select StudentLastName from DemoTable into outfile 'E:\StudentLastName.txt'; Query OK, 5 rows affected (0.00 sec)
The file location is ‘E:\StudentLastName.txt’. The screenshot of file and contents are as follows. We have successfully export column data to the file −
- Related Questions & Answers
- How to export data frame in R to excel?
- How do I force the column alias to be of specific data type in MySQL?
- How to arrange data in s specific order in MySQL?
- Swap a specific column value in MySQL
- How to find tables with a specific column name in MySQL?
- Export Data from a SAP system
- How to get a specific column record from SELECT query in MySQL?
- Fetch a specific column value (name) in MySQL
- MySQL query to split a column after specific characters?
- MySQL query to count rows with a specific column?
- MySQL insert a value to specific row and column
- How can we export all the data from MySQL table into a text file?
- How can we export all the data from MySQL table into a CSV file?
- How to sum selected column values based on specific month records in MySQL?
- How to change the column position of MySQL table without losing column data?
Advertisements