How can I perform multi-table joint query in a data structure like a movie website?

Source: Internet
Author: User
For example, each movie has multiple tags, and each tag has multiple movies. The typical relationship is many-to-many. Therefore, I have created an intermediate table: fm_movie_tag, which has two fields: movie_id and tag_name. Movie_id and tag_name correspond to one table. For details about each movie...


For example, each movie has multiple tags, and each tag has multiple movies. A typical relationship is many-to-many. So I created an intermediate table: fm_movie_tag.
This table has two fields: movie_id and tag_name. Movie_id and tag_name correspond to one table.
For the data table fm_moviedetail with detailed information about each movie, you can set two fields: Region (movie_area) and age (movie_year ), now I want to query the sci-fi movies in Europe and America in 2015. How can I write this SQL statement?

Reply content:


For example, each movie has multiple tags, and each tag has multiple movies. A typical relationship is many-to-many. So I created an intermediate table: fm_movie_tag.
This table has two fields: movie_id and tag_name. Movie_id and tag_name correspond to one table.
For the data table fm_moviedetail with detailed information about each movie, you can set two fields: Region (movie_area) and age (movie_year ), now I want to query the sci-fi movies in Europe and America in 2015. How can I write this SQL statement?

SELECT md.name FROM fm_movie_tag AS fmtLEFT JOIN fm_moviedetail AS md ON md.id = fmt.movie_idLEFT JOIN fm_tagdetail AS td ON td.id = fmt.tag_idWHERE md.movie_area = 'xx' AND md.movie_year = 'xx' AND td.name = 'xx';

2015 is also a tag, isn't it simple? tag in (2015, Europe and America, science fiction)

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.