Home > Database > Mysql Tutorial > How can we copy data with certain conditions from existing MySQL table?

How can we copy data with certain conditions from existing MySQL table?

王林
Release: 2023-08-28 08:25:02
forward
1292 people have browsed it

我们如何从现有的 MySQL 表中复制带有某些条件的数据?

As we all know, we can copy data and structures from existing tables through CTAS scripts. If we want to copy data with certain conditions then we need to use WHERE clause with CTAS script. Consider the following example -

mysql> Create table EMP_BACKUP2 AS SELECT * from EMPLOYEE WHERE id = 300 AND Name = 'Mohan';
Query OK, 1 row affected (0.14 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> Select * from EMP_BACKUP2;
+------+-------+
| Id   | Name  |
+------+-------+
| 300  | Mohan |
+------+-------+

1 row in set (0.00 sec)
Copy after login

In the above example, we have created a table named EMP_BACKUP1 from the table "Employee" based on some conditions. MySQL creates a table with only one row based on these conditions.

The above is the detailed content of How can we copy data with certain conditions from existing MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template