LBFan9911@stripped wrote:
>
> I'm not sure if I'm posting this right, so if this is the wrong place to do
> this just delete this email.
>
> I have a question about MySQL select statements. I have a web site that
> interfaces with a large quantity of records. I want to do a keyword search.
> The results I want to order in the order of how many keywords were matched.
> So if 3 keywords are entered and all three are found, it displays these
> first, then it displays the ones where less than 3 were found.
>
> I was trying to do two searches. One with an AND - (field1 LIKE "%keyword1%"
> && field1 LIKE "%keyword2%"). Then I thought I would do the same type of
> SELECT using the OR function. The problem is I get duplicates from the first
> select statement that I don't want.
>
> Can I do something like:
> select * from my_table where field1 like "%keyword1%" && id not in (select
> id
> from my_table where field1 like "%keyword1%" && field1 like "%keyword2%");
>
> I am sure there is a better way but I do not have much experience beyond the
> basic SQL statements.
>
> Any help is greatly appreciated.
>
> Repectfully,
>
> Jaymes H. Sorbel
Hi Jaymes
You suggest the solution yourself.
First get the result for all ANDed and remember their IDs.
Then do an:
SELECT
*
FROM
my_table
WHERE
field1 LIKE "%keyword1%
AND id NOT IN ( remembered_list_komma_seperated )
;
Tschau
Christian