Subject | Re: There must be a better way. |
---|---|
Author | Adam |
Post date | 2005-09-02T01:02:34Z |
For you Nige, we will try
For an OR condition, would something like this work?
select distinct p.str_href
from tbl_PageWord p
join tbl_Words w on (p.Int_Word = w.Int_Word)
where w.str_word in ('Beer', 'Chocolate', '4WD')
Providing I understand your schema, it should be pretty quick
For an AND condition, try union
select p.str_href
from tbl_PageWord p
join tbl_Words w on (p.Int_Word = w.Int_Word)
where w.str_word in ('Beer')
union
select p.str_href
from tbl_PageWord p
join tbl_Words w on (p.Int_Word = w.Int_Word)
where w.str_word in ('Chocolate')
union
select p.str_href
from tbl_PageWord p
join tbl_Words w on (p.Int_Word = w.Int_Word)
where w.str_word in ('4WD')
You could off course change the IN clause to an =, but if you keep it
as IN then it will allow you to mix ANDs and ORs together. This
should work providing you don't get the query > 64K. There may be
more efficient ways if you are expected large numbers of members in
the AND clause.
Adam
For an OR condition, would something like this work?
select distinct p.str_href
from tbl_PageWord p
join tbl_Words w on (p.Int_Word = w.Int_Word)
where w.str_word in ('Beer', 'Chocolate', '4WD')
Providing I understand your schema, it should be pretty quick
For an AND condition, try union
select p.str_href
from tbl_PageWord p
join tbl_Words w on (p.Int_Word = w.Int_Word)
where w.str_word in ('Beer')
union
select p.str_href
from tbl_PageWord p
join tbl_Words w on (p.Int_Word = w.Int_Word)
where w.str_word in ('Chocolate')
union
select p.str_href
from tbl_PageWord p
join tbl_Words w on (p.Int_Word = w.Int_Word)
where w.str_word in ('4WD')
You could off course change the IN clause to an =, but if you keep it
as IN then it will allow you to mix ANDs and ORs together. This
should work providing you don't get the query > 64K. There may be
more efficient ways if you are expected large numbers of members in
the AND clause.
Adam