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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:04:05+00:00 2026-05-14T21:04:05+00:00

If it matters, I’m using Firebird 2.1 database. I have three tables, one with

  • 0

If it matters, I’m using Firebird 2.1 database.

I have three tables, one with keywords, one with negative keywords, and the other with required keywords. I need to be able to filter the data so the output has just the keywords that meat the stipulation of not being in the negative keyword list, and IF there are any required words, then it will require the results to have those keywords in the end result.

The tables are very similar, the field in the tables that I would be matching against are all called keyword.

I don’t know SQL very well at all. I’m guessing it would be something like SELECT keyword from keywordstable where keyword in requiredkeywordstable and where NOT in negativekeywordstable

Just a side note, The required keywords table could be empty which would mean there are no required keywords.

Any help would be appreciated.

Example Of Tables:

KeywordsTable
-Keywords varchar 255
RequiredKeywordsTable
-Keywords varchar 255
NegativeKeywordsTable
-Keywords varchar 255

Example Data:
KeywordsTable
Cat
Dog
Mouse
Horse
House

With Nothing set in the Negative and Required Keywords Tables then the output would simply be the Keywords Table data unchanged.

IF RequiredKeywordsTable has the value of Car, Cat, Dog then the output would be and Cat Dog

If NegativeKeywordsTable has the value of Horse and requiredkeywords was empty then the output of the Keywords table would be cat, dog, mouse, House.

etc..

-Brad

  • 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-14T21:04:06+00:00Added an answer on May 14, 2026 at 9:04 pm

    Your specification is a bit hazy. It would help if you provided some schema. Is the keywords table just words or is it a list of keywords for a given entity? What happens if there exists at least one RequiredKeyword but not all Keywords are required? Should the non-required keywords show or should only required keywords show in that scenario? If both required and non-required keywords should be returned, then how does the list of required keywords affect the outcome? Here are some possible solutions:

    Scenario 1:

    1. The three tables are keywords for a given entity key.
    2. The EntityKey is not nullable.
    3. If a given entity has a required keyword, then only required keywords should show.
    Select ...
    From Keywords As K
        Left Join NegativeKeywords As NK
            On NK.EntityKey = K.EntityKey
        Left Join RequiredKeywords As RK
            On RK.EntityKey = K.EntityKey
    Where NK.EntityKey Is Null
        And (
            Not Exists  (
                        Select 1
                        From RequiredKeywords As RK1
                        Where RK1.EntityKey = K.EntityKey
                        )
            Or RK.EntityKey Is Not Null
            )

    Scenario 2:

    1. Only the Keywords table is for a given entity key or is just words but the other two are a list of required and negative keywords.
    2. The Keyword column in all three tables is not nullable.
    3. If there exists even one required keyword, then only required keywords should show:
    Select ...
    From Keywords As K
        Left Join NegativeKeywords As NK
            On NK.Keyword = K.Keyword
        Left Join RequiredKeywords As RK
            On RK.Keyword = K.Keyword
    Where NK.Keyword Is Null
        And (
            Not Exists  (
                        Select 1
                        From RequiredKeywords As RK1
                        Where RK1.Keyword = K.Keyword
                        )
            Or RK.Keyword Is Not Null
            )

    Scenario 3:

    1. The Keywords table is just words
    2. The Keyword column in all three tables is not nullable.
    3. The system should return whether the given keyword is required or not but should also show non-required keywords.
    Select ...
        , Case When RK.Keywords Is Not Null Then 1 Else 0 End As IsRequired
    From Keywords As K
        Left Join NegativeKeywords As NK
            On NK.Keyword = K.Keyword
        Left Join RequiredKeywords As RK
            On RK.Keyword = K.Keyword
    Where NK.Keyword Is Null

    Addition

    Given your additional information, here is how you can solve the problem. First, based on what you said, I’m presuming the schema looks something like:

    Create Table Keywords( Keywords varchar(255) not null primary key )
    Create Table NegativeKeywords( Keywords varchar(255) not null primary key  )
    Create Table RequiredKeywords( Keywords varchar(255) not null primary key  )
    

    If the Keywords column is the only column, I would make it not nullable and the primary key. This ensures that you do not have duplicates and lets us rely on the fact that the column is not nullable to check for non-existence. The problem is significantly more difficult to solve if the Keywords column is nullable in the NegativeKeywords and/or RequiredKeywords table.

    Insert Keywords(Keywords) Values( 'Cat' )
    Insert Keywords(Keywords) Values( 'Dog' )
    Insert Keywords(Keywords) Values( 'Mouse' )
    Insert Keywords(Keywords) Values( 'Horse' )
    Insert Keywords(Keywords) Values( 'House' )
    
    Select ...
    From Keywords As K
        Left Join NegativeKeywords As NK
            On NK.Keywords = K.Keywords 
        Left Join RequiredKeywords As RK
            On RK.Keywords = K.Keywords 
    Where NK.Keywords Is Null
        And (
            Not Exists  (
                        Select 1
                        From RequiredKeywords As RK1
                        Where RK1.Keywords = K.Keywords
                        )
            Or RK.Keywords Is Not Null
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say on MySQL database (if it matters).
I have an application written in C#.Net (Framework 2.0 if it matters). It calls
I'm needing to cache some data using System.Web.Caching.Cache . Not sure if it matters,
Ok: This is some of my table structure that matters here CaseStudyID int Title
In the context of C++ (not that it matters): class Foo{ private: int x[100];
How can I convince Firefox (3.0.1, if it matters) to send an If-Modified-Since header
I'm working on a web app project (in java; not that it matters) and
In particular, I'm editing the AutoCompletion.plist file for CSSEdit (if that even matters). My
EDIT: I suppose I should clarify, in case it matters. I am on a
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business

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.