Mysql-experts help optimize SQL statements (not experts)

Source: Internet
Author: User
There are two tables, tb1, tb2tb1 table structure id (primary key), nametb2 table structure id (primary key), type (primary key), content, note, and datetype. the optional values are:, b, c, d, etb1, and tb2 are one-to-many relationships. id is used to associate the following data types... mySQL database SQL

There are two tables, tb1 and tb2.
Table structure of tb1
Id (primary key), name
Table structure of tb2
Id (primary key), type (primary key), content, note, date
Type: a, B, c, d, e

Tb1, tb2 is a one-to-many relationship, associated by id

For example, the following data

Tb1
Id name
01 tom
02 jim

Tb2
Id type content note date
01 a xxx1 xx1 20130102
01 B xxx2 x 2 20130103
01 c xxx3 xx3 20130103
01 d xxx4 xx4 20130103
01 e xxx5 xx5 20130103
02 B xxx4 xx4 20130103
02 e xxx5 xx5 20130103

I want to extract such data now

Id name type1 content1 note1 date1 type2 content2 note2 date2 type3 content3 note3 date3...
01 tom a xxx1 xx1 20130102 B xxx2 xx2 20130103 c xxx3 xx3 20130103...
02 jim B xxx4 xx4 20130103...

Write an SQL statement with the highest execution efficiency. I use MYSQL,
And do not use the so-called temporary table of MYSQL.

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.