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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:37:01+00:00 2026-06-15T12:37:01+00:00

I am trying to implement an idea where I have two sql tables in

  • 0

I am trying to implement an idea where I have two sql tables in a database.

Table Info which has a field Nationality and the other Table Exclusion which has a field Keyword.

`Info.Nationality`               `Exclusion.Keyword`

    |British|                     |France|  
    |resteraunt de France|        |Spanish|
    |German|
    |Flag Italian|
    |Spanish rice|
    |Italian pasta
    |Irish beef|

In my web application I am creating a GridView4 and through a DataTable and SqlDataAdapter I am populating that GridView4 with the SQL command:

SELECT DISTINCT Info.Nationality WHERE Exclusion.Keyword NOT LIKE '%Spanish%'

That SQL statement retrieves all the distinct records in Info.Nationality which do not contain the word spanish.

What I am currently doing is that in the web app which is in vb.net I am adding two different GridViews, each have the data of each table which means that GridView2 has DISTINCT Info.Nationality and GridView3 has Exclusion.Keyword and then adding another GridView4 to display the results of the above SQL command.

The idea is to retrieve all the distinct records from Info.Nationlity which are not suppressed by the keyword constraints in Exclusion.keyword. So from the above mentioned Sql command the GridView4 will retrieve all the records which do not have the word “Spanish”.

I am doing all of this in a nested for loop where in the first loop it takes each record (one by one) from Info.Nationality e.g.for each row As DataRow in Me.GridView2.Rows() and compare it with the second for loop which goes till the end of the Exclusion.Keyword which would be like For i=0 To Gridview3 - 1.

The problem is that in that sql statement I have to explicitly specify the word to compare. I tried adding the records of Exclusion.Keyword in a String and then replacing the Spanish Keyword In between the NOT LIKE with the name of the String which is Keywords and then assigning the name a parameter with cmd.parameter.addwithvalue(@String, Keywords). However this is not working, it is only comparing with the last record in the string and ignoring the first.

The idea behind all of this is to display all the records of Info.Nationality in GridView4 which do not contain the keywords in Exclusion.Keyword.

Is there an easier or more effecient way to do this? I was thinking of an Inner Join with a Like command but that is not my problem. My problem is that how can I compare each record one by one of Info.Nationlity with all the records in Exclusion.keyword and then retrieving the ones that do not match and discarding the ones that match.

Then in Gridview4 how can I edit the records without reflecting those changes or affecting in Info.Nationality but rather only Inserting to Exclusion.Keyword the changes.

SOLVED by adding ToString() after Text
In my asp.net web app, I tried this, but didn’t work: (SOLVED)

 `SELECT DISTINCT Nationality 
FROM Info Where NOT EXISTS(SELECT * FROM Exclusion WHERE Info.Nationality LIKE '%' + @GridView +'%')`

`cmd.parameters.AddwithValue("@GridView", GridView3.Rows(i).Cells(0).Text.ToString())`

GridView3 Here has the Exclusion.Keywords data.

Would really appreciate your suggestions and thoughts around this.

  • 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-15T12:37:03+00:00Added an answer on June 15, 2026 at 12:37 pm

    You do not need to do this one-by-one, or “Row by agonizing row” as some DBAs are fond of describing this type of approach. There are lots of ways to write a query to only return the records from Info.nationality that do not match the exclusion keywords as a single expression.

    My preference is to use the EXISTS clause and a correlated subquery:

    SELECT Nationality 
    FROM Info I
    WHERE NOT EXISTS(SELECT * FROM Exclusion WHERE I.Nationality LIKE '%' + Keyword + '%')
    

    You can also express this as a left join.

    SELECT I.Nationality 
    FROM Info I
        LEFT OUTER JOIN Exclusion E 
            ON I.Nationality LIKE '%' + E.Keyword + '%'
    WHERE E.Keyword IS NULL 
    

    The left join will return all the rows from info and insert nulls in the columns for Exclusion except where the join criteria matches. By filtering for only where those values are null, you can avoid the matches.

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

Sidebar

Related Questions

I have an idea I'm trying to implement. I want to display half a
I'm trying to implement anti-aliased pixel rendering. My basic idea is to render 4
I'm trying implement A* Start path finding in my games(which are written with JavaScript,
I have been trying to implement Chris Coyier's inline-block + text justify solution to
I have an application consisting of two windows, one communicates to the other and
I'm trying to implement row-based security checks for Django models. The idea is that
Hi, I am trying to fetch data from two tables using join but i
I am trying to implement a WF4 activity extension which to handle some long
I have an idea I have yet to implement, because I have some fear
So I have this idea and I think it's basically impossible to implement in

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.