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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:14:06+00:00 2026-05-10T14:14:06+00:00

Let’s say I have four tables: PAGE , USER , TAG , and PAGE-TAG

  • 0

Let’s say I have four tables: PAGE, USER, TAG, and PAGE-TAG:

Table      | Fields ------------------------------------------ PAGE       | ID, CONTENT TAG        | ID, NAME USER       | ID, NAME     PAGE-TAG   | ID, PAGE-ID, TAG-ID, USER-ID 

And let’s say I have four pages:

PAGE#1 'Content page 1' tagged with tag#1 by user1, tagged with tag#1 by user2  PAGE#2 'Content page 2' tagged with tag#3 by user2, tagged by tag#1 by user2, tagged by tag#8 by user1   PAGE#3 'Content page 3' tagged with tag#7 by user#1 PAGE#4 'Content page 4' tagged with tag#1 by user1, tagged with tag#8 by user1 

I expect my query to look something like this:

select page.content ? from page, page-tag  where  page.id = page-tag.pag-id  and page-tag.tag-id in (1, 3, 8)  order by ? desc 

I would like to get output like this:

Content page 2, 3 Content page 4, 2 Content page 1, 1 

Quoting Neall

Your question is a bit confusing. Do you want to get the number of times each page has been tagged?

No

The number of times each page has gotten each tag?

No

The number of unique users that have tagged a page?

No

The number of unique users that have tagged each page with each tag?

No

I want to know how many of the passed tags appear in a particular page, not just if any of the tags appear.

SQL IN works like an boolean operator OR. If a page was tagged with any value within the IN Clause then it returns true. I would like to know how many of the values inside of the IN clause return true.

Below i show, the output i expect:

page 1 | in (1,2)   -> 1  page 1 | in (1,2,3) -> 1  page 1 | in (1)     -> 1  page 1 | in (1,3,8) -> 1  page 2 | in (1,2)   -> 1  page 2 | in (1,2,3) -> 2  page 2 | in (1)     -> 1  page 2 | in (1,3,8) -> 3  page 4 | in (1,2,3) -> 1  page 4 | in (1,2,3) -> 1  page 4 | in (1)     -> 1  page 4 | in (1,3,8) -> 2 

This will be the content of the page-tag table i mentioned before:

   id       page-id  tag-id  user-id        1       1        1       1       2       1        1       2       3       2        3       2       4       2        1       2       5       2        8       1       6       3        7       1       7       4        1       1       8       4        8       1  

@Kristof does not exactly what i am searching for but thanks anyway.

@Daren If i execute you code i get the next error:

#1054 - Unknown column 'page-tag.tag-id' in 'having clause'  

@Eduardo Molteni Your answer does not give the output in the question but:

Content page 2 8 Content page 4 8 content page 2 3 content page 1 1 content page 1 1 content page 2 1 cotnent page 4 1 

@Keith I am using plain SQL not T-SQL and i am not familiar with T-SQL, so i do not know how your query translate to plain SQL.

Any more ideas?

  • 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. 2026-05-10T14:14:07+00:00Added an answer on May 10, 2026 at 2:14 pm

    OK, so the key difference between this and kristof’s answer is that you only want a count of 1 to show against page 1, because it has been tagged only with one tag from the set (even though two separate users both tagged it).

    I would suggest this:

    SELECT page.ID, page.content, count(*) AS uniquetags FROM    (  SELECT DISTINCT page.content, page.ID, page-tag.tag-id        FROM page INNER JOIN page-tag ON page.ID=page-tag.page-ID        WHERE page-tag.tag-id IN (1, 3, 8)     )     GROUP BY page.ID 

    I don’t have a SQL Server installation to check this, so apologies if there’s a syntax mistake. But semantically I think this is what you need.

    This may not give the output in descending order of number of tags, but try adding:

          ORDER BY uniquetags DESC 

    at the end. My uncertainty is whether you can use ORDER BY outside of grouping in SQL Server. If not, then you may need to nest the whole thing in another SELECT.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have such MYSQL table for logins: id---name---location---login_date ---------------------------------- 1----mike----usa-----21.08.2012 2----tony----uk------22.08.2012 3----tony----uk------23.08.2012
Let's say I have a method in java, which looks up a user in
Let's say I have a table with a Color column. Color can have various
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have window.open (without name parameter), scattered in my project and I
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have an facebook application running using the JS SDK. First user
let's say I have a select list as follows: <select name='languages'> <option value='german'>German</option> <option
Let's say I have many items with click event (all have same element name

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.