- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 can we export some field(s) from MySQL table into a CSV file?
It can be done by providing the column(s) names in the SELECT … INTO OUTFILE statement while exporting the data from MySQL table into a file. We are illustrating it with the help of the following example −
Example
Suppose we are having following data from table ‘Student_info’ −
mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | +------+---------+------------+------------+ 6 rows in set (0.07 sec)
Suppose we want only two columns ‘id’ and ‘Name’ from the above table to be exported into a file then the following query can export the values of only ‘id’ and ‘name’ from ‘Student_info’ table into a file named ‘student1.csv’ −
mysql> Select id, Name from Student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student1.csv'; Query OK, 6 rows affected (0.07 sec)
The above query will create a file named ‘Student1.csv’ and export the values of columns ‘id’ and ‘name’ from ‘Student_info’ table into it.
- Related Articles
- How can we export some field(s) from MySQL table into a text file?
- How can we export all the data from MySQL table into a CSV file?
- How can we import data from .CSV file into MySQL table?
- How can I export values based on some conditions from MySQL table into a file?
- How can we export all the data from MySQL table into a text file?
- How MySQL evaluates if we export the data to CSV file from a table which contains a NULL value(s)?
- How can we store any other value than N in CSV file if we export the data to CSV file from a table which contains a NULL value(s)?
- What kind of settings can we do to a CSV file by query while exporting the values from MySQL table into a CSV file?
- How can we import data from .txt file into MySQL table?
- How can we import the text file, having some line prefixes, into MySQL table?
- How can we copy data with some condition/s from existing MySQL table?
- How can we import only specific columns from the text file, into MySQL table?
- How can we export data to a CSV file along with columns heading as its first line?
- How can we export data to a CSV file whose filename name contains timestamp at which the file is created?
- Python Tkinter – How to export data from Entry Fields to a CSV file?

Advertisements