Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select data from a table and insert into another table?

I want to select specific fields of a table in cassandra and insert them into another table. I do this in sql server like this:

INSERT INTO Users(name,family)
SELECT name,family FROM Users

How to to this in cassandra-cli or cqlsh?

like image 898
ehsan shirzadi Avatar asked Jan 26 '14 11:01

ehsan shirzadi


People also ask

Can we insert data from one table to another table?

The SQL INSERT INTO SELECT StatementThe INSERT INTO SELECT statement copies data from one table and inserts it into another table. The INSERT INTO SELECT statement requires that the data types in source and target tables match. Note: The existing records in the target table are unaffected.

How do I transfer data from one table to another in database?

Launch SQL Server Management Studio. Select and right-click on the Source Database, go to Tasks > Export Data. Import/Export Wizard will be opened and click on Next to proceed. Enter the data source, server name and select the authentication method and the source database.

How do I copy data from one table to another with different columns?

Click the tab for the table with the columns you want to copy and select those columns. From the Edit menu, click Copy. Click the tab for the table into which you want to copy the columns. Select the column you want to follow the inserted columns and, from the Edit menu, click Paste.


1 Answers

COPY keyspace.columnfamily1 (column1, column2,...) TO 'temp.csv';
COPY keyspace.columnfamily2 (column1, column2,...) FROM 'temp.csv';

here give your keyspace(schema-name) and instead of columnfamilyname1 use the table to which you want to copy and in columnfamily2 give the tablename in which you want to copy..

And yes this is solution for CQL,however I have never tried in with CLI.

like image 143
Helping Hand.. Avatar answered Oct 02 '22 14:10

Helping Hand..