Click to See Complete Forum and Search --> : Retrievein only the records with the given int_cod


amrigo
05-22-2006, 12:46 PM
Hi
I would like to retrieve only the results with int_cod = 13
(maintaining the others filters)
but in the code below i do get many int_cod different than 13

How it be done to retrieve only the recoerds with int_cod 13 ?

SELECT * FROM the_database
WHERE 1=1
AND int_cod =13
AND ( txt_text LIKE '%oneword%' OR txt_other_text LIKE '%oneword%' )
OR ( txt_text LIKE '%oneword%' OR txt_other_text LIKE '%oneword%' )
OR ( txt_text LIKE '%oneword%' OR txt_other_text LIKE '%oneword%' )
OR ( txt_text LIKE '%oneword%' OR txt_other_text LIKE '%oneword%' )
and int_published = 1

GaryS
05-22-2006, 12:52 PM
The 1=1 bit looks a bit strange.

amrigo
05-22-2006, 01:09 PM
I agree the where 1=1 is there i donītr know wich reason why
just to donīt care with the where clause

Know i do use having at the last line of the statemente and it work fine

chazzy
05-22-2006, 01:39 PM
it's because you have an illogical piece there. your or's aren't grouped in a single () so they evaluate separately

try this

SELECT * FROM the_database
WHERE 1=1
AND int_cod =13
AND (( txt_text LIKE '%oneword%' OR txt_other_text LIKE '%oneword%' )
OR ( txt_text LIKE '%oneword%' OR txt_other_text LIKE '%oneword%' )
OR ( txt_text LIKE '%oneword%' OR txt_other_text LIKE '%oneword%' )
OR ( txt_text LIKE '%oneword%' OR txt_other_text LIKE '%oneword%' ))
and int_published = 1