A MySQL statement that asks for a three-table associated query

Source: Internet
Author: User
You, beg for a SQL statement, I got a long time to get out of the wrong, the results are duplicates, trouble to help me see thank you ah.

Three tables, content, relationship, Meta,

Content is the contents, the primary key CID;
Meta Table Storage Classification of the corresponding name, type, etc., primary key mid;
Relationship is a relationship between content and Meta, two keys, CID and corresponding mid.

To get a SQL is to give a category name, say default, to find out the contents of the content and meta content into the array.
PS. A bit like WordPress inside the database structure, find a half-day did not find WP is how to achieve ... It's weak.

I tried to write a few, but all a bit wrong, join did not learn, trouble everyone help, thank you.

Reply content:

You, beg for a SQL statement, I got a long time to get out of the wrong, the results are duplicates, trouble to help me see thank you ah.

Three tables, content, relationship, Meta,

Content is the contents, the primary key CID;
Meta Table Storage Classification of the corresponding name, type, etc., primary key mid;
Relationship is a relationship between content and Meta, two keys, CID and corresponding mid.

To get a SQL is to give a category name, say default, to find out the contents of the content and meta content into the array.
PS. A bit like WordPress inside the database structure, find a half-day did not find WP is how to achieve ... It's weak.

I tried to write a few, but all a bit wrong, join did not learn, trouble everyone help, thank you.

It's done.

SELECT * from Hycms_metas as Mright JOIN hycms_relationships as r in M.mid = R.midjoin hycms_contents as C on r.cid = C.ci Dwhere 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.