Hi,
I'm trying to build a SQL query that would use LIKEP to return the record best matching some keywords or fallback to a default record (if it exists) if the keywords cannot be found.
For instance, let's say I have the following table
DocID | PageID | PlainText
id1 | 1 | 'this is page 1'
id1 | 2 | 'this is page 2'
id1 | 3 | 'this is page 3'
id2 | 1 | 'no matching text here'
id2 | 2 | 'no matching text here'
Right now I run the following query
select max($rank), DocId, Abstract from myTable where DocId in ('id1', 'id2', 'id3') and PlainText likep 'page 2' group by DocId which will return only the
record (DocId=id1, pageId=2) because the likep doesn't match any records for id2.
Now how can I modify the query to have it return (id2, pageId=1) too? In other words, if it doesn't find the keywords in the PlainText fields any record with DocId=id2, then it should return the record with pageId=1.
Note that the result should not contain a (DocId=id3, PageId=1) entry because there is no entry with DocId=id3 in the table
Thanks,
/Tony
I'm trying to build a SQL query that would use LIKEP to return the record best matching some keywords or fallback to a default record (if it exists) if the keywords cannot be found.
For instance, let's say I have the following table
DocID | PageID | PlainText
id1 | 1 | 'this is page 1'
id1 | 2 | 'this is page 2'
id1 | 3 | 'this is page 3'
id2 | 1 | 'no matching text here'
id2 | 2 | 'no matching text here'
Right now I run the following query
select max($rank), DocId, Abstract from myTable where DocId in ('id1', 'id2', 'id3') and PlainText likep 'page 2' group by DocId which will return only the
record (DocId=id1, pageId=2) because the likep doesn't match any records for id2.
Now how can I modify the query to have it return (id2, pageId=1) too? In other words, if it doesn't find the keywords in the PlainText fields any record with DocId=id2, then it should return the record with pageId=1.
Note that the result should not contain a (DocId=id3, PageId=1) entry because there is no entry with DocId=id3 in the table
Thanks,
/Tony