Select*fromStudent_info;+------+---------+------- -----+------------+|id |Name |Address |Subject |+---"/> Select*fromStudent_info;+------+---------+------- -----+------------+|id |Name |Address |Subject |+---">

Home >Database >Mysql Tutorial >How to export values ​​based on certain criteria from a MySQL table to a file?

How to export values ​​based on certain criteria from a MySQL table to a file?

WBOY
WBOYforward
2023-09-15 20:17:05926browse

如何将基于某些条件的值从 MySQL 表导出到文件中?

We can use conditions in the WHERE clause while exporting data from a MySQL table to a file. It can be understood through examples -

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete