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

  • Home
  • SEARCH
  • 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 880723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:08:44+00:00 2026-05-15T12:08:44+00:00

I’ve got a settings table constructed with ‘category’ determining different products, ‘varname’ being the

  • 0

I’ve got a settings table constructed with ‘category’ determining different products, ‘varname’ being the variable name, and ‘info’ being the value of the setting.

so, for instance,

select top 6 category, varname, info 
from settings_table 
where NODE_NAME='HTT-COMM-A' 
  and section='Module Settings' 
  and category in  ('ProductA', 'ProductB') 
order by varname

results in :

 category   varname             info  
 ProductB   WEB_ACCESS_ALLOW    NO  
 ProductA   WEB_ACCESS_ALLOW    NO  
 ProductB   WEB_ACCESS_BLOCK    YES  
 ProductA   WEB_ACCESS_BLOCK    YES  
 ProductB   WEB_ACCOUNT_DETAIL  NO  
 ProductA   WEB_ACCOUNT_DETAIL  YES  

I’d like to generate a simple list of differences between the values when category=’ProductA’ and ‘ProductB’. I can think of a number of ways to do this with a temporary table, or by a number of subselects (for instance, this painful one) :

select a.category, a.varname, a.info , b.category, b.info 
from (select category, varname, info, description
      from settings_table 
      where category = 'ProductA') as a,
     (select category, varname,info, description 
      from settings_table 
      where category = 'ProductB') as b 
where a.varname=b.varname and a.info != b.info

but the above method (at least) fails when there’s a varname in b that isn’t in a. (Any solutions should fix this problem, any differences in varnames between a and b should be represented as well.)

This isn’t a hard problem to solve in a kludgy way, but I wonder if there’s a ‘right way’ to do this elegantly, without the horrid sub-selects or without the caveats above.

This is more SQL agnostic, but this particular table is in a MSSQL server.

Thanks,
Rk

  • 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-15T12:08:44+00:00Added an answer on May 15, 2026 at 12:08 pm

    If you only cared about the varname and info values, you could do something like:

    Select varname, info
    From @Data As T
    Except  (
            Select varname, info
            From @Data As T1
            Where category = 'ProductA'
            Intersect
            Select varname, info
            From @Data As T2
            Where category = 'ProductB'
            )
    

    If you wanted other columns from the source table, then you can do something like:

    Select T.*
    From settings_table As T
        Left Join   (
                    Select T1.varname, T1.info
                    From settings_table As T1
                    Where T1.category = 'ProductA'
                        And T1.NODE_NAME='HTT-COMM-A' 
                        And T1.section='Module Settings'
                    Intersect
                    Select T2.varname, T2.info
                    From settings_table As T2
                    Where T1.category = 'ProductB'
                        And T1.NODE_NAME='HTT-COMM-A' 
                        And T1.section='Module Settings'
                    ) As Z
            On Z.varname = T.varname
                And Z.info = T.info
    Where Z.varname Is Null
        And T.NODE_NAME='HTT-COMM-A' 
        And T.section='Module Settings'
    

    Yet a third way would be to simply use an EXISTS predicate:

    Select T.*
    From settings_table As T
    Where T.NODE_NAME='HTT-COMM-A' 
        And T.section='Module Settings'
        And Not Exists  (
                        Select 1
                        From settings_table As T2
                        Where T2.category In('ProductA','ProductB')
                            And T2.varname = T.varname
                            And T2.info = T.info
                        Group By T2.varname, T2.info
                        Having Count(*) = 2
                        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.