How to organize mysql table fields

Source: Internet
Author: User
The following article mainly describes how to sort out the mysql table fields correctly. This article describes the specific steps of the operations in a single question and answer, which will give you a deeper understanding, the following describes the specific content of the article. I hope you will gain some benefits after browsing it. Table dz_tupian: mysql table field phidadress001wha

The following article mainly describes how to sort out the mysql table fields correctly. This article describes the specific steps of the operations in a single question and answer, which will give you a deeper understanding, the following describes the specific content of the article. I hope you will gain some benefits after browsing it. Table dz_tupian data mysql table field phid adress 001wha

The following article mainly describes how to sort out the mysql table fields correctly. This article describes the specific steps of the operations in a single question and answer, which will give you a deeper understanding, the following describes the specific content of the article. I hope you will gain some benefits after browsing it.

Table dz_tupian

Data in the current table

Mysql table field phid adress

 
 
  1. 001 whai
  2. 002 fdsadf
  3. 003 fdsfsdaf
  4. 002 dfewads
  5. 003 fwerasere
  6. 001 hfghgrtt
  7. ... ...

Expected results:

Field phid adress

 
 
  1. 001 whai hfghgrtt
  2. 002 fdsadf dfewads
  3. 003 fdsfsdaf fwerasere

There are many identical numbers in the phid to identify the duplicates first (there may be one or 60)

Then combine duplicate rows into one row ---- the second mysql table field adress with the same phid

Add it to the adress field of the newly integrated row

This is my idea. I don't know how to write code.

Question added: the second method is quite good. query in the mysql database and export the query results to get the expected results.

However, the adress type of the dz_tupian field is mediumtext. The maximum length of mediumtext is 16777215 characters.

Why are the exported query results incomplete? We can see that the adress value of the same phid is not completely added to the adress field.

Why?

The problem does not seem to be the limit on the number of characters in the adress field. However, if the number of characters in the same phid is large, the corresponding adress will be displayed if the number of characters in the last few are incomplete.

I have just checked that the adress field contains a maximum of 533 characters, but the adress type of the mysql table field is mediumtext. mediumtext has a maximum length of 16777215 characters. This is why it is incomplete. Why ????

Level-1 best answer:

The group_concat function has a size limit. The default value is 1024. You can modify the size according to your requirements. There are two methods:

1. Add the following in the mysql configuration file:

Group_concat_max_len = 102400 # maximum length you want

2. You can simply execute the statement:

 
 
  1. mysql> SET GLOBAL group_concat_max_len=102400;
  2. Query OK, 0 rows affected (0.01 sec)

For details, refer to the connection of reference materials.

Mysql can use the group_concat function. The following statement is passed in mysql 5.

 
 
  1. select phid,group_concat(adress order by adress separator " ") as adress
  2. from dz_tupian
  3. group by phid

The above content is an introduction to the integration of mysql table fields. I hope you will have some gains.

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.