473,588 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL or C# for searching one table based on another table's data?

I have a table of keywords (hundreds/thousands of records):

KeywordID KeywordName
--------- -----------
1 Apple
2 Orange
3 Pear
I then have a table of products (also hundreds/thousands of records):

ProductID ProductName ProductDescript ion
--------- ----------- ------------------------------------
123 Apple Tree Better than an orange tree, this...
124 Great Scent This great scent smells like orange...
What's the most efficent way to search the entire product table and return
all records that have any of the keywords from the keyword table (in eiter
productname or peoductdescript ion)?

DO YOU THINK I'm going to need to send all this data to a DataSet and
iterate through in C# code, or do you think I could do it all in a proc?

Thanks,
Ron
Mar 31 '07 #1
3 2596
I'd think something like:

Select <columns or whatever you wantfrom Products Where ProductName
like '%Apple%' OR ProductDescript ion like '%Apple%' would return very
quickly from any of the major database engines. Using a sql stored
procedure would be even better.

Iterating in c# ought to be slower since this is a set-based question
by nature.

Bob Graham

Ronald S. Cook wrote:
I have a table of keywords (hundreds/thousands of records):

KeywordID KeywordName
--------- -----------
1 Apple
2 Orange
3 Pear
I then have a table of products (also hundreds/thousands of records):

ProductID ProductName ProductDescript ion
--------- ----------- ------------------------------------
123 Apple Tree Better than an orange tree, this...
124 Great Scent This great scent smells like orange...
What's the most efficent way to search the entire product table and return
all records that have any of the keywords from the keyword table (in eiter
productname or peoductdescript ion)?

DO YOU THINK I'm going to need to send all this data to a DataSet and
iterate through in C# code, or do you think I could do it all in a proc?

Thanks,
Ron
Mar 31 '07 #2
Or are you looking for a cartesian product, all records multiplied by
all matches? That would tax either system I would think. I'm no expert
but I think this qualifies as a many-to-many result set, and with
thousands of records in both tables the answer could be huge,
especially if some Products table items have multiple matches in them!

Bob Graham
Ronald S. Cook wrote:
I have a table of keywords (hundreds/thousands of records):

KeywordID KeywordName
--------- -----------
1 Apple
2 Orange
3 Pear
I then have a table of products (also hundreds/thousands of records):

ProductID ProductName ProductDescript ion
--------- ----------- ------------------------------------
123 Apple Tree Better than an orange tree, this...
124 Great Scent This great scent smells like orange...
What's the most efficent way to search the entire product table and return
all records that have any of the keywords from the keyword table (in eiter
productname or peoductdescript ion)?

DO YOU THINK I'm going to need to send all this data to a DataSet and
iterate through in C# code, or do you think I could do it all in a proc?

Thanks,
Ron
Mar 31 '07 #3
Ronald S. Cook wrote:
I have a table of keywords (hundreds/thousands of records):

KeywordID KeywordName
--------- -----------
1 Apple
2 Orange
3 Pear
I then have a table of products (also hundreds/thousands of records):

ProductID ProductName ProductDescript ion
--------- ----------- ------------------------------------
123 Apple Tree Better than an orange tree, this...
124 Great Scent This great scent smells like orange...
What's the most efficent way to search the entire product table and
return all records that have any of the keywords from the keyword
table (in eiter productname or peoductdescript ion)?

DO YOU THINK I'm going to need to send all this data to a DataSet and
iterate through in C# code, or do you think I could do it all in a
proc?
First, enable full text indexes on the database and buld a fulltext index
for the Product table. That'll improve query speed.

You can write the query easily in SQL:

select
distinct p.*
from
Product p
join Keyword k
on p.ProductName like '%'+k.KeywordNa me+'%'
or p.ProductDescri ption like '%'+k.KeywordNa me+'%'

there are many variations of the query possible, but that one should get you
started (i.e. it may not be the most efficient, but it will work).

If what you really want is a list of Products that contain each and every
keyword (which isn't exactly what you asked for, but seems like something
you might want):

select
k.KeywordID,
p.ProductID
from
KeyWord k
join Product p
on p.ProductName like '%'+k.KeywordNa me+'%'
or p.ProductDescri ption like '%'+k.KeywordNa me+'%'

That'll get you a table ot tuples of (KeywordID,Prod uctID).

It's very unlikely that a solution that ships all this data back to some C#
code via a dataset will give better performance - network latency and
bandwidth alone will dominate that solution as the tables get larger.

-cd
Mar 31 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14900
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data in the format that I need it in order to create the reports that we use. So far this has proven to be successful for the reports that I am doing and the data that I am pulling into it. I just have one challenge that may require a lot of work and I...
0
1434
by: Jason | last post by:
I would like to be able to place a command button on a primary (parent) form that opens up a subform. I want to use this subform to search for or limit the recordset of data in the primary form. The database is setup as follows: the primary form is named "TestDataCleanup" which is based on a table named "Test_Results". This primary form has multiple subforms associated with it, including "Names_Display" and "SiteAddresses_Display". The...
0
1543
by: Jason | last post by:
I would like to be able to place a command button on a primary (parent) form that opens up a subform. I want to use this subform to search for or limit the recordset of data in the primary form. The database is setup as follows: the primary form is named "TestDataCleanup" which is based on a table named "Test_Results". This primary form has multiple subforms associated with it, including "Names_Display" and "SiteAddresses_Display". The...
5
8820
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is this possible? I have not been able to make it happen. Dim objKeys(2) as Object objKeys(0) = "CL" objKeys(2) = 4000 Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
33
2461
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following criteria: I have a list of about 100 numbers which correspond to the ID field and also another 40 say numbers corresponding to the numbers in the PRODUCT field. I want to show the rows that correspond to both these criteria.
3
1334
by: ANDY AIYER | last post by:
Guru's! Your time and guidance is much appreciated in this task that i am trying to get done. Background I have a SQL Server 2000 database table which contains 2 Fields (RecordID, XMLData (datatype=TEXT). There are about 10,000 records in this table. The Data in the field (XMLData) is a XML formatted string. (where F1,F2... are
5
2386
by: justobservant | last post by:
When more than one keyword is typed into a search-query, most of the search-results displayed indicate specified keywords scattered throughout an entire website of content i.e., this is shown as three bolded periods '...' in search-result listings. Additionally, most content is outdated; as many users need up-to-date content. Hence, filtering-through search-results becomes quite cumbersome. The newsgroup listings allow detailed...
5
17673
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600. The species list has 7 fields the first is a four digit unique identifier (species) it is set as the primary key. I have created a relationship to the data collection table which also has a species field (4 digit id). In my form I have the species...
3
3277
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a "Searching..." page then, refreshes and displays the table I want. I have code that grabs data from the page using cURL but when I look at the data it contains the "Searching..." page and not the table that I want. below is the code i have so far....Thanks...
0
7862
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2372
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.