How does dolphindb specify column names like MySQL when inserting data? - mysql

I have a table with hundreds of lines, and I just want insert some column data, and how to specify column name, in mysql I can write
insert into joke (gid,name)value(0,”joker”);

It is not possible and also unnecessary
Insert new records to a table.
Syntax:
insert into
table_name1
values (X, [Y], ...) | select col_name(s) from table_name2
Online manual for INSERT INTO

Related

Insert specific values into mysql database

I have the following problem:
I would't insert all the values in my db.
So, i would insert only id,tessera,nome,sex. I thought i had to write something like this:
INSERT INTO registries(id,tessera,'',nome,sex) VALUES (35983,35983,'DOG', 'FABIO', 'M')
I don't want to insert the DOG value in my db cause I don't have any attribute in my schema to save it.
I have 3000 rows and I take this row as example so I can't simply delete the DOG value and the attribute field in my sql query.
I remember that I have to use something like this
INSERT INTO registries(id,tessera,'',nome,sex)
I mean, I have to write '' to not consider the value in that position.
but MySQL gives me an error..
Can you help me?
You can handle this situation in following ways.
create temporary table on same server. Insert all data in temporary table then use insert into select statement and select required fields.
create temporary column and insert data in that column and delete temporary column
INSERT INTO registries (id,tessera,new_column,nome,sex)
VALUES (35983, 35983, '', 'FABIO', 'M');
Now
DROP COLUMN new_column from registries;
Try this (assuming dog is a column name):
INSERT INTO registries (id,tessera,dog_name,nome,sex) VALUES (35983, 35983, '', 'FABIO', 'M')
If dog_name is allowed to be NULL (which it is by default) you could also just not insert any value, like this:
INSERT INTO registries (id,tessera,nome,sex) VALUES (35983, 35983, 'FABIO', 'M')

how to check row number while importing data

We have database table 'field_data_body' and we are using 'insert into ... select from' mysql command to insert data into 'field_data_body' from another table.
Table structure:
In our database table, delta column is used to differentiate same record. For example,
In above exmaple, both row has same data except different value of delta.
How can we set delta while inserting data into database table?
I have search in google and some other questions in stack exchange but did not find solutions.
Thanks in advance.
You could use 2 queries for that.
insert into tablename (col1, col2, ..) Values (value1, value2, ..);
insert into tablename (delta) Values (value) where entity_type = 'node';

Database INSERT INTO SET ... WHERE(SELECT ...)

I am trying to insert my values into table if Admin_User_Role_Id value against Admin_Id is not present in the table. Is it possible to insert!
My Table Structure:
Admin_User_Id (FK)
Admin_User_Role_Id (FK)
Is_Enabled (boolean flag)
Query which I tried, but not success
INSERT INTO role_association
SET Admin_User_Id=61, Admin_User_Role_Id=2, Is_Enabled=0
WHERE Admin_User_Role_Id
NOT IN
(SELECT Admin_User_Id, Admin_User_Role_Id FROM role_association)
I think it is possible but my logic is wrong. How should I manage this query to work successfully!
INSERT syntax cannot have WHERE clause. The only time you will find INSERT has WHERE clause is when you are using INSERT INTO...SELECT statement.
Probably you take care about where condition in your programming logic and write a simple insert statement and the depending on your logic use this statement to insert the records. Hope you got my point.
You want to insert your values in your table using this query for your reference
INSERT INTO Yourtablename(column1,column2,column3,...)
VALUES ('value1','value2','value3',.....);
You want to ADD one new column in your table means using this query
** ALTER TABLE table_name ADD column_name datatype**

MySQL multiple insert: How to write a query to insert the new rows and ignore inserting duplicate rows?

I want to insert multiple rows in a MySQL table at once. One of the columns, column c, of that table is unique indexed. How to write a query to insert the new rows(rows where value of column c is not equal to the column c value of any previously inserted row) only and ignore inserting duplicate rows?
You can use INSERT IGNORE instead of insert.Query will be like this .
INSERT IGNORE INTO person_tbl (last_name, first_name)
VALUES( 'Jay', 'Thomas');

Trouble with MAX(col)+1 INSERT into same MySQL table

I need two id columns in the same table that create unique values upon insert. Since MySQL allows only one column to auto-increment, I need to do something like max(id)+1 for the other column.
Here's the SQL I expected to work:
INSERT INTO invoices (invoiceid)
VALUES ((SELECT MAX(invoiceid)+1 FROM invoices))
The select statement works independently, but within my INSERT, it's not allowed. I get the error : You can't specify target table 'invoices' for update in FROM clause
You want to use INSERT INTO .... SELECT FROM instead of INSERT INTO...VALUES():
INSERT INTO invoices (invoiceid)
SELECT MAX(invoiceid)+1
FROM invoices
My question for you would be why are you not use an AUTO INCREMENT field to generate the invoiceid value? That is what it is for, then you will not have to create this when inserting data.