Navicat,mysql Common operations

Source: Internet
Author: User

Navicat Copy a shortcut to all the fields in a table

阅读数:2708有时需要复制一个表里的所有的字段用来拼写sql字段 列表,并且还需要以逗号连接。可用sql查:1.这种是以逗号连接的字段列表:select group_concat(COLUMN_NAME) from information_schema.COLUMNS where table_name = ‘表名‘;2.直接显示字段,蓝色标记部分可不写SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE table_name=‘表名‘  and TABLE_SCHEMA=‘数据库名‘ ;

The use of the INSERT into select from MySQL

How to combine fields from multiple tables in MySQL and then insert them into a new table, implemented by an SQL statement. The case is: there are three tables A, B, C, now you need to check the values of several fields from table B and table C into the corresponding fields in table A. In this case, we can use the following statement to implement:

   INSERT INTO db1_name(field1,field2) SELECT field1,field2 FROM db2_name      

Of course, the above statement is more suitable for two tables of data interpolation, if more than one table is not adapted. For multiple tables, we can first join the fields that need to be queried, then compose a view and select from:

   INSERT INTO a(field1,field2) SELECT * FROM(SELECT f1,f2 FROM b JOIN c) AS tb      其中f1是表b的字段,f2是表c的字段,通过join查询就将分别来自表b和表c的字段进行了组合,然后再通过select嵌套查询插入到表a中,这样就满足了我们这个场景了,如果需要不止2个表,那么可以多个join的形式来组合字段。需要注意的是嵌套查询部分最后一定要有设置表别名,如下:   SELECT * FROM(SELECT f1,f2 FROM b JOIN c) AS tb      即最后的as tb是必须的(当然tb这个名称可以随意取),即指定一个别名,否则在mysql中会报如下错误:   ERROR 1248 (42000): Every derived TABLE must have its own alias      即每个派生出来的新表都必须指定别名才可以的。

Refer:https://www.cnblogs.com/jpfss/p/6973048.html

69938983

Navicat,mysql Common operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.