mysql -e 'SELECT * FROM table' > out.txt
load data local infile 'out.txt' into table 'some_table'
mysql -e 'SELECT * FROM table' > out.txt
load data local infile 'out.txt' into table 'some_table'
A useful (but seemingly underused) SQL keyword is the IF statement.
The usage is as follows:
SELECT IF(expr1, expr2, expr3);
If expr1 evalues to true, then expr2 is executed, otherwise, expr3 is. This is useful for doing conditional queries inside the SQL without having to put logic in your script/program.
SELECT IF( (SELECT name FROM people) = 'john'), (SELECT age FROM people WHERE name = 'john') , 'no age');
The above statement will return the age of the user ‘john’ if he exists in the people table. If not the query will return ‘no age.’
The caveat is that expr2 and expr3 must evaluate to a single value. The braces around expr2′s SELECT statement are required.
Copying a data with all the structure and data in tact.
CREATE TABLE newtable (SELECT * FROM oldtable);