D
djc
I have a specific question about being able to retrieve records based on a
certian condition which I will describe below. However, please also let me
know if you think my table structure is not a good idea or if you have other
ways which you think are better for doing this. The basic idea here is being
able to search for records based on one or several keywords.
The 2 tables:
tblMain: (I'll call them articles for this posts description's sake)
MainID
Title
Description
tblKeywords:
MainID
Keyword
tblMain: (example data)
101, How to make stew, description.....
102, vba trim() info, description....
103, Whats in stew, description....
tblKeywords (example data)
101, stew
101, cooking
101, food
102, vba
102, trim
102, programming
103, stew
103, food
So, given one user search field I intend on letting the user type in
multiple keywords seperated by spaces (similar to a google or yahoo search)
and then parsing that to get my multiple keywords. From these keywords I
will construct an SQL statement to find the appropriate records. So my
specific question comes in here. I know I can easily implement a logical OR
operator to get all the records (articles) that have at least one of the
keywords supplied by the user in the tblKeywords table but what about giving
the option to perform an AND logical comparison? Since the tblKeywords table
will have multiple entries for each article but one keyword per record,
simply saying 'WHERE keyword = input1 AND keyword = input2' would always be
false. How could I return only the articles that meet the requirment of
having several keywords? Like a user entering 'cooking AND stew' in the
input box should return 101, How to make stew, but NOT 103, Whats in stew.
anyone? any input is greatly appreciated.
certian condition which I will describe below. However, please also let me
know if you think my table structure is not a good idea or if you have other
ways which you think are better for doing this. The basic idea here is being
able to search for records based on one or several keywords.
The 2 tables:
tblMain: (I'll call them articles for this posts description's sake)
MainID
Title
Description
tblKeywords:
MainID
Keyword
tblMain: (example data)
101, How to make stew, description.....
102, vba trim() info, description....
103, Whats in stew, description....
tblKeywords (example data)
101, stew
101, cooking
101, food
102, vba
102, trim
102, programming
103, stew
103, food
So, given one user search field I intend on letting the user type in
multiple keywords seperated by spaces (similar to a google or yahoo search)
and then parsing that to get my multiple keywords. From these keywords I
will construct an SQL statement to find the appropriate records. So my
specific question comes in here. I know I can easily implement a logical OR
operator to get all the records (articles) that have at least one of the
keywords supplied by the user in the tblKeywords table but what about giving
the option to perform an AND logical comparison? Since the tblKeywords table
will have multiple entries for each article but one keyword per record,
simply saying 'WHERE keyword = input1 AND keyword = input2' would always be
false. How could I return only the articles that meet the requirment of
having several keywords? Like a user entering 'cooking AND stew' in the
input box should return 101, How to make stew, but NOT 103, Whats in stew.
anyone? any input is greatly appreciated.