Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is that SQL SELECT possible 1

Status
Not open for further replies.

pss08

Programmer
Mar 10, 2006
7
ES
I have a table with, say, patients.

In that table I have multiple records for each patient with a memo field on it. Is it possible to filter patients that have records containing some text.

For example, I need to know how many patients that in the memo field of one of his records contains "headache", and in the memo field of another record of the same patient contains "aspirin" on it.

 
I can search in the Memo field using LIKE, but what I need is to know what patients have records with some values. I can not do the following:

SELECT PacCode FROM PacHistory WHERE MemoHist LIKE '*headache*' AND MemoHist LIKE '*aspirin*'

or

SELECT PacCode FROM PacHistory WHERE MemoHist LIKE '*headache*' OR MemoHist LIKE '*aspirin*'

Because there is a record that contains '*headache*' and another different record that contains '*aspirin*' both pertaining to the same patient. I need to know the patients that have only both kind of records.
 
You may try this:
SELECT A.PacCode
FROM PacHistory A INNER JOIN PacHistory B ON A.PacCode = B.PacCode
WHERE A.MemoHist LIKE '*headache*' AND B.MemoHist LIKE '*aspirin*'


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top