Evaluate a MySQL statement for a three-table join query

Source: Internet
Author: User
Ladies and gentlemen, it is always wrong for me to find an SQL statement by myself and there are repeated items in the result. Please help me check it out. Thank you. Three tables: content, relationship, meta, content is content, primary key cid, meta table Storage Class name, type, etc., primary key mid; re... ladies and gentlemen, it is always wrong for me to find an SQL statement by myself and there are repeated items in the result. Please help me check it out. Thank you.

Three tables: content, relationship, meta,

Content is content, primary key cid;
The name and type of the meta table Storage category. The primary key is mid;
Relationship is the relationship between content and meta. There are two keys: cid and the corresponding mid.

An SQL statement is to give a category name, for example, default, to find the relevant content and meta content into an array.
PS. It's a bit like the database structure in Wordpress. I haven't found out how WP is implemented after a long time ...... Weak

I tried to write a few articles, but they are not correct. JOIN is not good. Please help me. Thank you.

Reply content:

Ladies and gentlemen, it is always wrong for me to find an SQL statement by myself and there are repeated items in the result. Please help me check it out. Thank you.

Three tables: content, relationship, meta,

Content is content, primary key cid;
The name and type of the meta table Storage category. The primary key is mid;
Relationship is the relationship between content and meta. There are two keys: cid and the corresponding mid.

An SQL statement is to give a category name, for example, default, to find the relevant content and meta content into an array.
PS. It's a bit like the database structure in Wordpress. I haven't found out how WP is implemented after a long time ...... Weak

I tried to write a few articles, but they are not correct. JOIN is not good. Please help me. Thank you.

Done.

SELECT * FROM hycms_metas AS mRIGHT JOIN hycms_relationships AS r ON m.mid = r.midJOIN hycms_contents AS c ON r.cid = c.cidWHERE m.slug =  'default'AND m.mid IS NOT NULL

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.