Mysql executes multi-table queries, big data, and SQL statements.

Source: Internet
Author: User
Mysql executes multi-table queries, big data, and SQL statements. Assume that two tables are a B. The two tables have the same structure. Now we need to retrieve all the fields in Table A and the set and rutime fields in Table B. The IDs of the two tables are the same.

Because the data volume is large, the two tables are around, and there may be multiple such large tables later.
In phpmyadmin

Select * from A as a, B as B where a. haoma = B. haoma

During the test, the system has run and died. Which of the following statements can help you write this SQL?


Reply to discussion (solution)

select ecs_ershi.* ,ecs_erjiu.set from ecs_ershi inner join ecs_erjiu on ecs_ershi.haoma=ecs_erjiu.haoma limit 0,29

I wrote this statement and the query was successful. However, if the data volume is large, it will die there.
How can I store the queried data in Table C?

Does it has indexes on A. haoma and B. haoma?

Does it has indexes on A. haoma and B. haoma?
What does it mean.

A. has haoma and B. haoma been indexed?

No index is created !!!

Is haoma a primary key? If not, create an index.

Select * from A as a, B as B where a. haoma = B. haoma
As long as an index is built on haoma, querying is just an instant
However, the output takes some time!
Do you print out all the 1 million records? Apparently, my head is faulty.

Direct
Insert into c (......)
Select ecs_ershi. *, ecs_erjiu.set
From ecs_ershi inner join ecs_erjiu on ecs_ershi.haoma = ecs_erjiu.haoma
Limit 0, 29
You can,

Do not output...

Select * from A as a, B as B where a. haoma = B. haoma
As long as an index is built on haoma, querying is just an instant
However, the output takes some time!
Do you print out all the 1 million records? Apparently, my head is faulty.
I am here to get points.

Select * from A as a, B as B where a. haoma = B. haoma
As long as an index is built on haoma, querying is just an instant
However, the output takes some time!
Do you print out all the 1 million records? Apparently, my head is faulty.
After the query is made, what else can be quickly printed after paging processing.

This should reflect the role of the index. Querying millions of records is slow.

1. as mentioned above, create a valid index
2. create a sub-table if the data size increases later
3. the table structure involves the separation of long characters into the new table
4. query using stored procedures

Phpmyadmin execution is too slow (set_time_limit (0);) in php. ini, you can try navicate for mysql

Desc select * from A as a, B as B where a. haoma = B. haoma adds an index to the table quickly. if you have A where condition query, you can add a full-text index.

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.