473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Lost 'in' SQL - need help with IN function

Hi guys, I have a database table (documents) with a structure that
looks like this:
docID docName keyWords
1 testTitle01.doc dog,cat,bob
2 testTitle02.doc hello,world
3 testTitle03.doc please,help,me
4 testTitle04.doc is,that,a,dog
5 testTitle05.doc it,wasnt,me
6 testTitle06.doc you,are,funny
7 testTitle07.doc as,a,clown

I want to write a SQL query that accepts a users input and searches
the keyword fields. I am not sure how to do this because the user
input will be in the format of: The,cat,ate,the,mouse and it will be
assinged to a form field called keyWordInput.

If there is an easy way to do this, I would greatly appreciate any
assistance.

Regards,

Evan
Jul 20 '05 #1
1 1102
You should drop the "Keywords" column and put the keywords in a separate
table. Non-atomic columns are a violation of basic design principles and
your problem problem is much easier to solve if you fix the design first.
Assuming you create a table like this:

CREATE TABLE DocumentKeywords (docid INTEGER NOT NULL REFERENCES Documents
(docid), keyword VARCHAR(30) NOT NULL, PRIMARY KEY (keyword,docid))

Your client application can then pass the keywords to a query like this:

SELECT DISTINCT D.docid, D.docname
FROM Documents AS D,DocumentKeywords AS K
WHERE D.docid = K.docid
AND K.keyword IN (@keyword1,@keyword2,@keyword3, ...)

Alternatively, use another table populated with your keyword search
criteria:

CREATE TABLE KeyWordSearch (session_id INTEGER NOT NULL, keyword VARCHAR(30)
NOT NULL, PRIMARY KEY (keyword, session_id))

SELECT DISTINCT D.docid, D.docname
FROM Documents AS D,DocumentKeywords AS K, KeyWordSearch AS S
WHERE D.docid = K.docid
AND K.keyword = S.keyword
AND S.session_id = @session_id

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2

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

Similar topics

5
by: Simon Redmond | last post by:
my hosting provider just upgraded the server and now some of my scripts don't work.... Fatal error: Call to undefined function: imagecreatefromjpeg() What do I need to look for in order to...
1
by: D. Shane Fowlkes | last post by:
I have a asp:textbox which I've applied a javascript function to strip off all non-numeric chanarcters. The js function is triggered with the textbox's onblur attribute. I also have a...
6
by: Lost Student | last post by:
Hello guys Any help that you can offer would be greatly appreciated. I am nearing the end of a C++ class and am so lost. The following is my assignment and what I have so far. Please help ...
9
by: Metaosp | last post by:
Hi, How can I call a function through function pointer while keeping the default argument value working? I mean: void foo(int i=3) { cout << i << endl; } void (*bar)(int);
0
by: silvrique | last post by:
I am totally lost. I have an xml script example as follows: <?xml version="1.0" encoding="utf8" ?> <starter> <second> <name>Silver</name> </second> </starter>
3
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As...
4
by: Frank | last post by:
Hello everyone, I have a problem that the window.opener variable is lost once my popup page has a postback. On multiple pages they address this problem but I cannot find a correct answer. ...
1
by: Cage26 | last post by:
First, I need to rewrite the program to incorporate functions. And there should be a value returning function that returns an int that the user entered. It will be called 5 times, once for each...
10
by: sam.barker0 | last post by:
Hi there, I am trying to develop a compressed suffix trie. But first I want to get the trie working. The structure of the trie is like class trie { private: bool last_node; map<char,...
13
by: esteban | last post by:
I need to know how can obtain the id of a element when this lost focus, the reason is because I have more than one editbox and my function needs of the id for validation, could you help me with a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.