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 302167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:04:21+00:00 2026-05-12T07:04:21+00:00

I have this tables: Posts (post_is, title and text), Tags (tag_id, tag), Post_tag_nn (id,

  • 0

I have this tables: Posts (post_is, title and text), Tags (tag_id, tag), Post_tag_nn (id, tag_id, post_id). I want for a specific post having for example 4 tags all the posts with those tags, then all the posts with any three of those tags, then all posts with any two of those tags and so on. How can i build a SQL query for this purpose (in php it seems like a backtracking problem=all the subsets of a given set).

  • 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-05-12T07:04:22+00:00Added an answer on May 12, 2026 at 7:04 am

    Have a query to find the tags of the current post, something like

    SELECT tag_id
    FROM Post_tag_nn
    WHERE post_id = $post_id;
    

    Then using those tag id’s, this query should return you the id’s of posts with 4,3,2,… matching tags:

    SELECT post_id, COUNT(post_id) AS tag_count
    FROM Post_tag_nn
    WHERE tag_id IN ($array_of_tag_ids)
    GROUP BY post_id
    ORDER BY tag_count DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have three tables, posts, images and postimages (this simply contains the ids
I have a posts table structured this way: id | title | content |
I have a table posts that could look like this: id | title |
I have this mysql tables I want to display with jqgrid. The problem appears
i have this three tables. Table: Item Columns: ItemID, Title, Content, NoChange (Date) Table:
I have the following tables; CREATE TABLE IF NOT EXISTS `tags` ( `tag_id` int(11)
you have this 2 tables: table1 ------------- id fromId fromOtherTableId person and Table2 -------------
I have Cinema table & City table and I have relation with this tables
I have Movie table & TblMovieVideos table and I have relations with this tables,
I have two tables: This is table1: product_id|product_desc|product_name|product_s_desc This is table2: product_price_id|product_id|product_price Now I

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.