Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:17:29+00:00 2026-06-14T18:17:29+00:00

Please consider the following project table: Project: table: project manyToMany: themes: targetEntity: Theme inversedBy:

  • 0

Please consider the following project table:

Project:
  table: project
  manyToMany:
    themes:
      targetEntity: Theme
      inversedBy: projects
      joinTable:
        name: project_theme
        joinColumns:
          project_id:
            referencedColumnName: id
        inverseJoinColumns:
          theme_id:
            referencedColumnName: id
    platforms:
      targetEntity: Platform
      joinTable:
        name: project_platform
        joinColumns:
          project_id:
            referencedColumnName: id
        inverseJoinColumns:
          platform_id:
            referencedColumnName: id
  manyToOne:
    client:
      targetEntity: Client

As you can see a project has three relations; themes through the project_theme join table, platforms through the project_platform table and clients through a client_id column.

I'm trying a produce a query which will find all related projects - projects with the same themes, platforms or clients - and order them by a 'score'.

For example:

Project A:
  Themes: 18, 19
  Platforms: 1, 4
  Client: 22

Find related projects to Project A..

Project D:
  Themes: 18, 19
  Platforms: 1, 4
  Client: 22
Score: 5
Project G:
  Themes: 18, 21
  Platforms: 3, 4
  Client: 22
Score: 3
Project B:
  Themes: 8, 21
  Platforms: 2, 4
  Client: 1
Score: 1

I'd really appreciate some assistant with writing a MySQL query for this. I've been struggling for a while with the following - but I'm probably miles off:

SELECT 
    `project`.*,
    GROUP_CONCAT(`project_theme`.`theme_id`) as themes,
    GROUP_CONCAT(`project_platform`.`platform_id`) as platforms,
    `project`.`client_id` as client
FROM `project`
LEFT JOIN `project_theme` ON `project`.`id` = `project_theme`.`project_id`
LEFT JOIN `project_platform` ON `project`.`id` = `project_platform`.`project_id`
GROUP BY `project`.`id`

Many thanks in advance for any help
Pete

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:17:30+00:00Added an answer on June 14, 2026 at 6:17 pm

    Thanks for your hint Marlin, after reading Advance query. Rank most related fields in mysql and a bit of experimentation I think I might have cracked it…

    SELECT 
        p.*,
        (
            IFNULL(themes.matches, 0) + IFNULL(platforms.matches, 0) + IFNULL(clients.matches, 0)
        ) as score
    FROM `project` p
    LEFT JOIN (
        SELECT t2.project_id, COUNT(*) as matches FROM `project_theme` t1, `project_theme` t2
        WHERE 
          t1.theme_id = t2.theme_id AND t1.project_id = 1
          GROUP BY t2.project_id
    ) themes ON p.id = themes.project_id
    LEFT JOIN (
        SELECT f2.project_id, COUNT(*) as matches FROM `project_platform` f1, `project_platform` f2
        WHERE 
          f1.platform_id = f2.platform_id AND f1.project_id = 1
          GROUP BY f2.project_id
    ) platforms ON p.id = platforms.project_id
    LEFT JOIN (
        SELECT p2.id, COUNT(*) as matches FROM `project` p1, `project` p2
        WHERE 
          p1.client_id = p2.client_id AND p1.id = 1
          GROUP BY p2.id
    ) clients ON p.id = clients.id
    GROUP BY p.`id`
    HAVING score > 0
    ORDER BY score DESC;
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please Consider the following table : As you can see the Name column has
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Please consider the following tweets table: tweet_id user_id text ---------------------------- 1 1 lorem ipsum
Please consider following sample table structure: +-------------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null |
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
Please consider the following view: <p>Count <span data-bind=text: unreadCount()>&nbsp;</span></p> <div data-bind='template: { name: conversationTemplate,
Please consider the following code, <form action=index.php method=post name=adminForm enctype=multipart/form-data> <input type=hidden name=showtime[] id=showtime_1
Please consider following tables. Table: Document docID, docNr, docScanTime 10, 99, 2012-08-02 11, 98,
Please consider following snippet: <div class=row> <div class=span12> <div class=control-group> <label class=control-label>Person Name</label> <div
Please consider the following table structure and data: +--------------------+-------------+ | venue_name | listed_by |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.