Question : mysql nested SELECT

I have a table called criteriahistory.
criteriahistoryID, historyID, criteria, itemdate, criteriaID

Sample:
222   71   jason                2007-05-02      172
223   71   scott                2007-05-02      173
224   71   logan                2007-05-02      174
225   72   john                  2007-05-03      172

I am trying to write a sql select statement that will allow me to get the historyID but allow me to find the criteria of more than one hit per historyID.

If I search for 'jason scott' I want historyID 71 to be pulled from the db.  BUT how do I write that because if I put (criteria LIKE '%jason%' AND criteria LIKE '%scott%') then 0 is returned because the criteria field isn't both jason and scott.  If I use OR instead of AND I get records that don't contain BOTH jason and scott.

I thought a nested select would do it but I don't know how to do it because it would be on the same record when the nested select would hit also.

I need something that can search the criteria column giving the same historyID number and pull out the historyID where ALL matches of criteria was hit giving that one historyID.

Thanks,
Jason

Answer : mysql nested SELECT

>>What would it look like if I entered jason scott logan as my search?

We could be looking at a 3rd table JOINed in.


Select T1.HistoryID
from criteriahistory T1 Inner Join criteriahistory T2 ON
  T1.HistoryID = T2.HistoryID
       AND T1.Criteria like '%jason%'
       AND T2.Criteria like '%scott%' Inner Join CriteriaHistory T3 ON
  T1.historyID = T3.historyID
       AND T3.Criteria like '%logan%'

This concept obviously doesn't scale very well.  How many names are you going to need to put in?
Random Solutions  
 
programming4us programming4us