- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 copy data with some condition/s from existing MySQL table?
152 Lectures 16 hours
87 Lectures 5.5 hours
As we know that we can copy the data and structure from an existing table by CTAS script. If we want to copy data with some condition/s then we need to use WHERE clause with CTAS script. Consider the example below −
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)
In the example above, we have created a table named EMP_BACKUP1 from table ‘Employee’ with some conditions. MySQL creates the table with only one row based on those conditions.
- 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 create a new MySQL table by selecting specific column/s from another existing table?
- How can we create a table from an existing MySQL table in the database?
- How can we get some last number of characters from the data stored in a MySQL table’s column?
- How can we get some starting number of characters from the data stored in a MySQL table’s column?
- How can I create a MySQL view that takes the values from a table based on some condition(s)?
- How can we insert data into an existing MySQL table by using PHP script?
- How can we add columns with default values to an existing MySQL table?
- Can we update MySQL with if condition?
- 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 modify column/s of MySQL table?
- How can we add multiple columns, with single command, to an existing MySQL table?
- How can we remove NOT NULL constraint from a column of an existing MySQL table?