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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:33:34+00:00 2026-06-04T09:33:34+00:00

I have a table similar to the following: REL_Aid_To_AttributeValue: ID AttributeValueID 101 1319 101

  • 0

I have a table similar to the following:

REL_Aid_To_AttributeValue:
ID    AttributeValueID
101   1319
101   1320
101   1344
101   1345
102   1319
102   1320
102   1321
102   1336
103   1320
103   1336

I have another table that groups these AttributeValueIDs by type:

TBL_AttributeValues:
AttributeValueID    AttributeTypeID
1319                1
1320                1
1321                1
1336                2
1344                3 
1345                3

I have a third table that gives information about each ID from the first table:

TBL_Aids:
ID     Title                Author       etc.
101    Aid About Spiders    John Doe
102    Aid About Mites      Jane Doe 
103    Aid About Beetles    Joe Schmo

I would like to return results of IDs (and information about them, like the Title, Author, etc.) that contain ONLY AttributeValueIDs 1319 OR (inclusive) 1320, within AttributeTypeID=1. So I would hope to return 101 because it only has 1319 and 1320 for AttributeType 1, and also 103 because it has only 1320 for AttributeType 1. I would not want to return 102 because although it has 1319 and 1320, it also has 1321, which is of AttributeType 1 as well.

I tried the following:

SELECT a.ID, a.Title, c.AttributeTypeID, 
COUNT(b.AttributeValueID)AS Total
FROM TBL_Aids as a,
REL_Aid_To_AttributeValue as b,
TBL_AttributeValues as c
WHERE a.ID=b.AidID
AND b.AttributeValueID=c.ID
AND a.Status=2
AND AttributeTypeID=1
AND (b.AttributeValueID=1319
OR b.AttributeValueID=1320)
GROUP BY a.ID, a.Title,
c.AttributeTypeID
HAVING COUNT(b.AttributeValueID) <= 2 

But it still returns 102 as a result, because it has already limited by 1319 and 1320 and is counting that total instead of the overall total of AttributeValueIDs for Type 1. Do I need some sort of subquery to accomplish this? Any help would be appreciated! Thank you so much.

  • 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-04T09:33:36+00:00Added an answer on June 4, 2026 at 9:33 am
    SELECT  id
    FROM    (
            SELECT  DISTINCT id
            FROM    REL_Aid_To_AttributeValue a
            WHERE   attributeValueId IN (1319, 1320)
            ) q
    WHERE   NOT EXISTS
            (
            SELECT  id
            FROM    (
                    SELECT  AttributeValueID
                    FROM    TBL_AttributeValues
                    WHERE   AttributeTypeID = 1
                            AND AttributeValueID NOT IN (1319, 1320)
                    ) t
            JOIN    REL_Aid_To_AttributeValue a
            ON      a.id = q.id
                    AND a.AttributeValueID = t.AttributeValueID
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table similar to the following: id key str_val date_val num_val 1
I have a large reporting table in Excel that looks similar to the following.
I have table similar to the following: Year | Product | Value 2006 A
I have a table similar to the following id | name | address both
I have a table similar to the following (of course with more rows and
I have a SqlServer2005 table Group similar to the following: Id (PK, int) Name
I have a table schema similar to the following (simplified): CREATE TABLE Transactions (
I have a Sql Database table similar to the following: Day Period Subject Mon
I have a table with rows similar to the following. These rows get updated
I have a table with a Name field containing data similar to the following:

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.