- 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 I export values based on some conditions from MySQL table into a file?
We can use the conditions in WHERE clause while exporting the data from MySQL table to a file. It can be understood with the help of an 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 to export the records having a value of id more than 120 then the following query will export such kind of records from ‘Student_info’ table into ‘Stuednt4.CSV’ file −
mysql> Select * from student_info WHERE id > 120 into outfile 'C:/mysql/bin/mysql-files/student4.csv' Fields terminated by ','; Query OK, 4 rows affected (0.16 sec)
The query above will export the following values into Student4.CSV file −
125 Raman Shimla Computers 130 Ram Jhansi Computers 132 Shyam Chandigarh Economics 133 Mohan Delhi Computers
- Related Articles
- How can we export some field(s) from MySQL table into a text file?
- How can we export some field(s) from MySQL table into a CSV file?
- 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 can I create a stored procedure to select values on the basis of some conditions from a MySQL table?
- How can I create a MySQL view that takes the values from a table based on some condition(s)?
- How can I search data from MySQL table based on similar sound values?
- How to write PHP script to fetch data, based on some conditions, from MySQL table?
- How can you select data from a table based on some criteria using MySQL in Python?
- SET only two values for all the rows in a MySQL table based on conditions?
- How can we import data from .txt file into MySQL table?
- How can we import data from .CSV file into MySQL table?
- How can we import the text file, having some line prefixes, into MySQL table?
- Delete only some rows from a table based on a condition in MySQL
- How can I create a stored procedure to delete values from a MySQL table?

Advertisements