We can use conditions in the WHERE clause while exporting data from a MySQL table to a file. It can be understood through examples -
Suppose we have the following data from the 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 records with id values greater than 120, then The following query will export such records from the "Student_info" table into the "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 above query will export the following values into the Student4.CSV file -
125 Raman Shimla Computers 130 Ram Jhansi Computers 132 Shyam Chandigarh Economics 133 Mohan Delhi Computers
The above is the detailed content of How to export values based on certain criteria from a MySQL table to a file?. For more information, please follow other related articles on the PHP Chinese website!