Mysql-join query, mysql-join

Source: Internet
Author: User

Mysql-join query, mysql-join
Three methods of MySQL association query:

SELECT * FROM film JOIN film_actor ON (film. film_id = film_actor.film_id );
SELECT * FROM film JOIN film_actor USING (film_id); -- when the field names of the two tables to be joined are the same, you can use USING ()
SELECT * FROM film, film_actor WHERE film. film_id = film_actor.film_id;

Optimize association query:
  • Make sure that the column in The ON or USING clause has an index. When creating an index, you must consider the order of association. In general, unless for other reasons, you only need to create an index on the corresponding column of the second table in the association sequence. For example, when the film and film_actor columns are associated with film_id. If the optimizer's association sequence is film_actor and film, you do not need to add an index to the film_id column of the film_actor table.
  • Make sure that any expressions in group by and order by only involve columns in a table, so that MySQL can use indexes to optimize the process.
  • When upgrading MySQL, note that the associated syntax, operator priority, and other issues may change. In the past, the common associations may become cartesian products, and different types of associations may generate different results.
Refer:

[1] Baron Schwartz; translated by Ninghai yuan; high-performance MySQL (version 3rd); Electronic Industry Press, 2013

Blog, http://www.jb51.net/article/68442.htm

Related Article

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.