MySQL common commands (advanced)


Sort out some commonly used Mysql commands that have been developed recently:

Inquire

Query the data of name that table b has but table a does not have
select name from b where name not in(select name from a);

query the data of id and name (multi-field query) that table b has but table a does not have
select id, name from b where (id,name) not in(select id,name from a);

select * from b where (id,name) not in(select * from a);

=================================================

renew

Update the field data of the specified field (single field)
update a set code=2018 where id=2014;

Update the field data of the specified field (multiple fields)
update a set code=2018 where (id,name)=(2014,'e' );

=================================================

get field

Get the fields of the data table
select column_name from information_schema.columns where table_schema='your 

databasename' and table_name='your tablename';

=================================================

copy new table

Create a table with the same fields as table b (copy structure)
create table a like b;

create a table with the same fields as table b (copy structure and data)
create table a select * from b;

=================================================

insert

Insert all the data in table b into table a (provided that the fields in table a and b are the same, and table a exists)
insert into a select * from b;

insert the data of the specified field in table b into table a (provided that in table a have these fields)

insert into a(id,name) select id,name from b;


Sort out some commonly used Mysql commands that have been developed recently:

Inquire

Query the data of name that table b has but table a does not have
select name from b where name not in(select name from a);

query the data of id and name (multi-field query) that table b has but table a does not have
select id, name from b where (id,name) not in(select id,name from a);

select * from b where (id,name) not in(select * from a);

=================================================

renew

Update the field data of the specified field (single field)
update a set code=2018 where id=2014;

Update the field data of the specified field (multiple fields)
update a set code=2018 where (id,name)=(2014,'e' );

=================================================

get field

Get the fields of the data table
select column_name from information_schema.columns where table_schema='your 

databasename' and table_name='your tablename';

=================================================

copy new table

Create a table with the same fields as table b (copy structure)
create table a like b;

create a table with the same fields as table b (copy structure and data)
create table a select * from b;

=================================================

insert

Insert all the data in table b into table a (provided that the fields in table a and b are the same, and table a exists)
insert into a select * from b;

insert the data of the specified field in table b into table a (provided that in table a have these fields)

insert into a(id,name) select id,name from b;


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324731798&siteId=291194637