473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

No results found for my search!

Dear all, I have illustared with code and sample output data my request
in thsi post. I simply was expecting some results from my search "amd
socket a 32 bit cache 512 dell" that includes a logical AND for all the
words in that search.
Since i assume that any word might be an item_name, item_key or
item_value, i included all in the search.

Can any one tell me why i get 0 results?

The sample output of my data should look like this:

item_id item_name item_key item_value
--------------------------------------------------
1 Gefore MX 440 Size 64 MB
1 Gefore MX 440 Architecture 64 Bit
1 Gefore MX 440 AGP 8x
1 Gefore MX 440 Chipset Nvidia
1 Gefore MX 440 Vendor Asus
2 AMD 3200+ Class Socket A
2 AMD 3200+ Speed 2 GHz
2 AMD 3200+ Architecture 32 Bit
2 AMD 3200+ Level 2 Cache 512 KB
2 AMD 3200+ Vendor AMD
3 Dell P780 Geometry 17 Inch
3 Dell P780 Screen Type Flat
3 Dell P780 Frequency 60 Hz
3 Dell P780 Vendor Dell

Here is my scenario:

create table item_table (item_id int identity (1,1) not null primary
key, item_name varchar (50) not null)
go
create table details_table (item_id int not null, item_key varchar
(50), item_value varchar (50))
go
alter table details_table add foreign key (item_id) references
item_table
go

insert into item_table values ('Gefore MX 440')
go
insert into item_table values ('AMD 3200+')
go
insert into item_table values ('Dell P780')
go

insert into details_table values (1,'Size', '64 MB')
go
insert into details_table values (1,'Architectur e', '64 Bit')
go
insert into details_table values (1,'AGP', '8x')
go
insert into details_table values (1,'Chipset', 'Nvidia')
go
insert into details_table values (1,'Vendor', 'Asus')
go

insert into details_table values (2,'Class', 'Socket A')
go
insert into details_table values (2,'Speed', '2 GHz')
go
insert into details_table values (2,'Architectur e', '32 Bit')
go
insert into details_table values (2,'Level 2 Cache', '512 KB')
go
insert into details_table values (2,'Vendor', 'AMD')
go

insert into details_table values (3,'Geometry', '17 Inch')
go
insert into details_table values (3,'Screen Type', 'Flat')
go
insert into details_table values (3,'Frequency', '60 Hz')
go
insert into details_table values (3,'Vendor', 'Dell')
go

create view all_view as
select top 100 percent i.item_id, i.item_name, d.item_key, d.item_value
from item_table as i left outer join details_table as d
on i.item_id = d.item_id
order by i.item_id, i.item_name, d.item_key, d.item_value
go

-- the complete search is "amd socket a 32 bit cache 512 dell"

declare @search_key1 as varchar (50)
declare @search_key2 as varchar (50)
declare @search_key3 as varchar (50)
declare @search_key4 as varchar (50)
declare @search_key5 as varchar (50)
declare @search_key6 as varchar (50)

set @search_key1 = 'amd'
set @search_key2 = 'socket a'
set @search_key3 = '32 bit'
set @search_key4 = 'cache'
set @search_key5 = '512'
set @search_key6 = 'dell'

select distinct item_id
from all_view
where
((item_name like '%' + @search_key1 + '%') or (item_key like '%' +
@search_key1 + '%') or (item_value like '%' + @search_key1 + '%'))
and
((item_name like '%' + @search_key2 + '%') or (item_key like '%' +
@search_key2 + '%') or (item_value like '%' + @search_key2 + '%'))
and
((item_name like '%' + @search_key3 + '%') or (item_key like '%' +
@search_key3 + '%') or (item_value like '%' + @search_key3 + '%'))
and
((item_name like '%' + @search_key4 + '%') or (item_key like '%' +
@search_key4 + '%') or (item_value like '%' + @search_key4 + '%'))
and
((item_name like '%' + @search_key5 + '%') or (item_key like '%' +
@search_key5 + '%') or (item_value like '%' + @search_key5 + '%'))
and
((item_name like '%' + @search_key6 + '%') or (item_key like '%' +
@search_key6 + '%') or (item_value like '%' + @search_key6 + '%'))
go

----

Best regards

Aug 24 '05 #1
20 2376
Stu
You don't have any one record that matches all of your criteria. Let
me try to step you through it real quick:

Your data:
item_id item_name item_key item_value
--------------------------------------------------
1 Gefore MX 440 Size 64 MB
1 Gefore MX 440 Architecture 64 Bit
1 Gefore MX 440 AGP 8x
1 Gefore MX 440 Chipset Nvidia
1 Gefore MX 440 Vendor Asus
2 AMD 3200+ Class Socket A
2 AMD 3200+ Speed 2 GHz
2 AMD 3200+ Architecture 32 Bit
2 AMD 3200+ Level 2 Cache 512 KB
2 AMD 3200+ Vendor AMD
3 Dell P780 Geometry 17 Inch
3 Dell P780 Screen Type Flat
3 Dell P780 Frequency 60 Hz
3 Dell P780 Vendor Dell

Your search: -- the complete search is "amd socket a 32 bit cache 512 dell"

Your WHERE clause:
((item_name like '%' + @search_key1 + '%') or (item_key like '%' +
@search_key1 + '%') or (item_value like '%' + @search_key1 + '%'))
crieria 1 finds all rows that have AMD in them:
2 AMD 3200+ Class Socket A
2 AMD 3200+ Speed 2 GHz
2 AMD 3200+ Architecture 32 Bit
2 AMD 3200+ Level 2 Cache 512 KB
2 AMD 3200+ Vendor AMD
and
((item_name like '%' + @search_key2 + '%') or (item_key like '%' +
@search_key2 + '%') or (item_value like '%' + @search_key2 + '%'))
the use of the and further narrows down your resultset to finding rows
with the second criteria: socket a
2 AMD 3200+ Class Socket A


the third criteria is 32 bit, which excludes the previous row from your
result set, so you get no results.

There are much better ways to do this design, but ultimately, you're
going to have to use an OR as part of your search criteria.

HTH,
Stu

Aug 24 '05 #2
Thanks for replying, Well with OR it will work, but i think because the
relationship between item_table and details_table is 1-M so all those
many details are within one or more items. Is there a way to find
results within all of them?
Actually the item_id 2 which is "AMD 3200+" does indeed have under it
all of the details "amd socket a 32 bit cache 512 dell" except "dell"
and item_id 3 which is "Dell P780" has under it the word "dell"; how is
it possible to include all without "OR"?
My reasoning is that the user searching will assume that he will get a
result that includes "All" as a must and not optional.

Best regards

Aug 24 '05 #3


coosa wrote:
Thanks for replying, Well with OR it will work, but i think because the
relationship between item_table and details_table is 1-M so all those
many details are within one or more items. Is there a way to find
results within all of them?
Actually the item_id 2 which is "AMD 3200+" does indeed have under it
all of the details "amd socket a 32 bit cache 512 dell" except "dell"
and item_id 3 which is "Dell P780" has under it the word "dell"; how is
it possible to include all without "OR"?
If you request items matching 'dell', you will get back
items matching 'dell' only, and you won't get back item #2.

Can you please show the exact result you want, since it sounds like
you don't want the result of using AND, but you don't want the result
of using OR. But your description "find results within all of them"
is not at all precise. It would help if you gave several examples
where neither OR nor AND gives you the results you want.
Steve Kass
Drew University
My reasoning is that the user searching will assume that he will get a
result that includes "All" as a must and not optional.

Best regards

Aug 24 '05 #4
Ok Steve, supposly without "dell". When I wrote that last post, i
didn't sleep since over 24 hours and i see now that "dell" was my own
mistake! :-) sorry for that.
The search would be "amd
socket a 32 bit cache 512". They are all under "AMD 3200+" which is
item_id 2. For this id those several specifications are not in one row,
but they belong to it.
I'd like a search like this with AND since i know they are all under
this id and hence it's an AND. For example, if i wrote "AMD 3200+ Speed
2 GHz" then there is a row that matches that. If i wrote then "32 Bit"
in addition to that, where "32 Bit" is under another row in the
details_table but still referes to item_id 2 and it's an AND, then
there are no results. I'd like to prevent that and make results happen!
Is this possible?

Aug 25 '05 #5
So for more code illustration:

declare @search_key1 as varchar (50)
declare @search_key2 as varchar (50)
declare @search_key3 as varchar (50)
declare @search_key4 as varchar (50)
declare @search_key5 as varchar (50)
declare @search_key6 as varchar (50)

set @search_key1 = 'amd'
set @search_key2 = 'socket a'
set @search_key3 = '32 bit'
set @search_key4 = 'cache'
set @search_key5 = '512'

select distinct item_id
from all_view
where
((item_name like '%' + @search_key1 + '%') or (item_key like '%' +
@search_key1 + '%') or (item_value like '%' + @search_key1 + '%'))
and
((item_name like '%' + @search_key2 + '%') or (item_key like '%' +
@search_key2 + '%') or (item_value like '%' + @search_key2 + '%'))
and
((item_name like '%' + @search_key3 + '%') or (item_key like '%' +
@search_key3 + '%') or (item_value like '%' + @search_key3 + '%'))
and
((item_name like '%' + @search_key4 + '%') or (item_key like '%' +
@search_key4 + '%') or (item_value like '%' + @search_key4 + '%'))
and
((item_name like '%' + @search_key5 + '%') or (item_key like '%' +
@search_key5 + '%') or (item_value like '%' + @search_key5 + '%'))
go

The View all_view:

item_id item_name item_key item_value
------------------------------*--------------------
2 AMD 3200+ Class Socket A
2 AMD 3200+ Speed 2 GHz
2 AMD 3200+ Architecture 32 Bit
2 AMD 3200+ Level 2 Cache 512 KB
2 AMD 3200+ Vendor AMD

For all the search keys which are:
'amd' + 'socket a' + '32 bit' + 'cache' + '512'
they ALL are specifications for item_id 2.
The real result I'd like to achieve is that it executes "select
distinct item_id" so it shows:

item_id 2

The user from the interface chooses "all of the words", "any of the
words" or "exact world phrase". When he/she chooses "all of the words"
he/she will be assuming that all of the words are mandatoray and must
exist. Maybe my table design is bad some how, but i need suggestions.

Best regards

Aug 25 '05 #6
Sorry for "dell", it was my mistake since i had been exhaused at the
time i was writing that last post and i appologize for that post.
For more code illustration:
declare @search_key1 as varchar (50)
declare @search_key2 as varchar (50)
declare @search_key3 as varchar (50)
declare @search_key4 as varchar (50)
declare @search_key5 as varchar (50)
set @search_key1 = 'amd'
set @search_key2 = 'socket a'
set @search_key3 = '32 bit'
set @search_key4 = 'cache'
set @search_key5 = '512'
select distinct item_id
from all_view
where
((item_name like '%' + @search_key1 + '%') or (item_key like '%' +
@search_key1 + '%') or (item_value like '%' + @search_key1 + '%'))
and
((item_name like '%' + @search_key2 + '%') or (item_key like '%' +
@search_key2 + '%') or (item_value like '%' + @search_key2 + '%'))
and
((item_name like '%' + @search_key3 + '%') or (item_key like '%' +
@search_key3 + '%') or (item_value like '%' + @search_key3 + '%'))
and
((item_name like '%' + @search_key4 + '%') or (item_key like '%' +
@search_key4 + '%') or (item_value like '%' + @search_key4 + '%'))
and
((item_name like '%' + @search_key5 + '%') or (item_key like '%' +
@search_key5 + '%') or (item_value like '%' + @search_key5 + '%'))
go
The View all_view:
item_id item_name item_key item_value
------------------------------**--------------------
2 AMD 3200+ Class Socket A
2 AMD 3200+ Speed 2 GHz
2 AMD 3200+ Architecture 32 Bit
2 AMD 3200+ Level 2 Cache 512 KB
2 AMD 3200+ Vendor AMD
For all the search keys which are:
'amd' + 'socket a' + '32 bit' + 'cache' + '512'
they ALL are specifications for item_id 2.
The real result I'd like to achieve is that it executes "select
distinct item_id" so it shows:
item_id 2
The user from the interface chooses "all of the words", "any of the
words" or "exact world phrase". When he/she chooses "all of the words"
he/she will be assuming that all of the words are mandatoray and must
exist. Maybe my table design is bad some how, but i need suggestions.

Those details in the table above, they show different rows; namely, a
pair of key and value per id. if one row is found, other search keys
that relate to other rows will be considered no results. Reality wise,
those other rows do belong to that particular item as a part of the
specifications and the user want an item that matches "all" of the keys
he/she entered.

I don't know if i illustrated enough, but looking forward to your reply

Best regards

Aug 25 '05 #7
On 25 Aug 2005 04:23:44 -0700, coosa wrote:
Sorry for "dell", it was my mistake since i had been exhaused at the
time i was writing that last post and i appologize for that post.
For more code illustration:

(snip)

Hi coosa,

Having the search strings in five variables makes this query lengthy.
Have you considered storing the search strings in a table? If you google
the Internet (or the newsgroups) for "Relational division", you'll find
the standard query to find sets of rows that match all rows in a second
table - you should be able to adapt those for your need.

However, the current design with five variables can be solved with this
(slow and repetitive) query:

SELECT DISTINCT v1.item_id, v1.item_name
FROM all_view AS v1
JOIN all_view AS v2
ON v2.item_id = v1.item_id
JOIN all_view AS v3
ON v3.item_id = v1.item_id
JOIN all_view AS v4
ON v4.item_id = v1.item_id
JOIN all_view AS v5
ON v5.item_id = v1.item_id
WHERE ( v1.item_name LIKE '%' + @search_key1 + '%'
OR v1.item_key LIKE '%' + @search_key1 + '%'
OR v1.item_value LIKE '%' + @search_key1 + '%')
AND ( v2.item_name LIKE '%' + @search_key2 + '%'
OR v2.item_key LIKE '%' + @search_key2 + '%'
OR v2.item_value LIKE '%' + @search_key2 + '%')
AND ( v3.item_name LIKE '%' + @search_key3 + '%'
OR v3.item_key LIKE '%' + @search_key3 + '%'
OR v3.item_value LIKE '%' + @search_key3 + '%')
AND ( v4.item_name LIKE '%' + @search_key4 + '%'
OR v4.item_key LIKE '%' + @search_key4 + '%'
OR v4.item_value LIKE '%' + @search_key4 + '%')
AND ( v5.item_name LIKE '%' + @search_key5 + '%'
OR v5.item_key LIKE '%' + @search_key5 + '%'
OR v5.item_value LIKE '%' + @search_key5 + '%')
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Aug 25 '05 #8
Thanks Hugo; i will look forward to read more about "Relational
division"

Aug 26 '05 #9
Perhaps something like

select item_id, item_name
from all_view
where not exists (
select * from (
select '%'+@search_key 1+'%' as like_key
union all select '%'+@search_key 2+'%'
union all select '%'+@search_key 3+'%'
union all select '%'+@search_key 4+'%'
union all select '%'+@search_key 5+'%'
) Keys
where not exists (
select * from all_view as V2
where V2.item_id = all_view.item_i d
and (
item_value like like_key or item_key like like_key
)
)
)

SK

coosa wrote:
Sorry for "dell", it was my mistake since i had been exhaused at the
time i was writing that last post and i appologize for that post.
For more code illustration:
declare @search_key1 as varchar (50)
declare @search_key2 as varchar (50)
declare @search_key3 as varchar (50)
declare @search_key4 as varchar (50)
declare @search_key5 as varchar (50)
set @search_key1 = 'amd'
set @search_key2 = 'socket a'
set @search_key3 = '32 bit'
set @search_key4 = 'cache'
set @search_key5 = '512'
select distinct item_id
from all_view
where
((item_name like '%' + @search_key1 + '%') or (item_key like '%' +
@search_key1 + '%') or (item_value like '%' + @search_key1 + '%'))
and
((item_name like '%' + @search_key2 + '%') or (item_key like '%' +
@search_key2 + '%') or (item_value like '%' + @search_key2 + '%'))
and
((item_name like '%' + @search_key3 + '%') or (item_key like '%' +
@search_key3 + '%') or (item_value like '%' + @search_key3 + '%'))
and
((item_name like '%' + @search_key4 + '%') or (item_key like '%' +
@search_key4 + '%') or (item_value like '%' + @search_key4 + '%'))
and
((item_name like '%' + @search_key5 + '%') or (item_key like '%' +
@search_key5 + '%') or (item_value like '%' + @search_key5 + '%'))
go
The View all_view:
item_id item_name item_key item_value
------------------------------**--------------------
2 AMD 3200+ Class Socket A
2 AMD 3200+ Speed 2 GHz
2 AMD 3200+ Architecture 32 Bit
2 AMD 3200+ Level 2 Cache 512 KB
2 AMD 3200+ Vendor AMD
For all the search keys which are:
'amd' + 'socket a' + '32 bit' + 'cache' + '512'
they ALL are specifications for item_id 2.
The real result I'd like to achieve is that it executes "select
distinct item_id" so it shows:
item_id 2
The user from the interface chooses "all of the words", "any of the
words" or "exact world phrase". When he/she chooses "all of the words"
he/she will be assuming that all of the words are mandatoray and must
exist. Maybe my table design is bad some how, but i need suggestions.

Those details in the table above, they show different rows; namely, a
pair of key and value per id. if one row is found, other search keys
that relate to other rows will be considered no results. Reality wise,
those other rows do belong to that particular item as a part of the
specifications and the user want an item that matches "all" of the keys
he/she entered.

I don't know if i illustrated enough, but looking forward to your reply

Best regards

Aug 26 '05 #10

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

Similar topics

6
4970
by: Alan | last post by:
I'm just about to start a project that needs to combine the results of a SQL Server query with the results of an Index Server query. The basic idea is that the user enters/selects a bunch of search criteria on a form. Most of the criteria selected by the user will be used to select records from the database - standard WHERE clause stuff - but...
5
2962
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine (a wicked phrase). Some but not all of the words of that phrase exist in my website. I reported it and they removed the link but did not give...
2
1374
by: Mark | last post by:
Hi Guys, I have a page with a list of links that when clicked submit data to a clients search engine, The result opens in another window and either displays a list of items or diaplays "No Items Found". I want to perform another action in my Asp Page if the result is "No Items Found" Can I get my Asp page to read the result from the...
0
1070
by: Paul Ganainm | last post by:
Hi all, This is not so much a question specific to PostgreSQL, but rather a general "application of theory" type of problem! I did post this on comp.databases.theory but received no replies there. If anyone here is interested and this is a suitable forum in the PostgreSQL hierarchy, that would be great! If this is not a good group,...
1
3531
by: Don | last post by:
I am new to Indexing Services, have been researching the MS Site as well as web articles on DevHood, etc. I have set up a seperate catalog ("KnowledgeBase") on Win XP with a number of files. I am trying to use OLEDB through ADO to search results and serve them up onto an ASP.Net web page, yet I consistently get back 0 results. I have this...
0
1330
by: Mad Scientist Jr | last post by:
When searching through code in Vis. Interdev 6, when in the Find dialog, it listed the results in the results pane below. The cursor didn't change position to the next found item until you clicked on a line in the results. This is actually a nice feature that I haven't seen before - all the matches show up at once in a list, with a column...
1
1616
by: russot00 | last post by:
I have 3 drop down menus that are used in a search to locate restaurants in a db. All of the drop down menus function, a search can be submitted with any combination of drop downs and the results are sorted by restaurant name. The problem occurs when you do not select anything from a drop down ("All" is submitted for all drop downs) and submit the...
3
1479
by: Bigalan | last post by:
Hello, i am relatively new to PHP and i am struggling with printing multiple search results on to different pages. The code below works ok but when you click on next page button, it brings up a blank screen. I think it might have something to do with resetting the $found variable. Can you have a quick look? any suggestions would be greatly...
1
2436
by: Ken Fine | last post by:
I have set up Microsoft Search Server 2008 Express. I want to know how I can query against it and return results in a form that can be bound to ASP.NET controls like ListViews. If there's simply a way to return results as an ArrayList or other data structure I can figure out the rest of this problem myself. What I don't want: * I don't...
19
2658
by: didacticone | last post by:
I created a search form that works well except when i am searching for a record that has multiple entries in the corresponding table. i would to filter the results so that they will display all the information associated with that record if there is more than one. here is my code that i am using. thanks for your help! Private Sub...
0
7614
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...
0
7924
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. ...
1
7676
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...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2114
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
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.