Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL SELECT ADV Question

Status
Not open for further replies.

sanjdhiman

Programmer
Jan 15, 2003
189
GB
Hi there I have a pretty easy question for u advanced SQL people

I have a table and it has been set out to store features of a property.

Features1

Features2

Features3

Features4

They are all varchar (50)

Ok so the problem is this

the user selects from a select box on form a keyword for example 'double glazing'

the select statement im trying to write has to search the table with the keyword 'double glazing' in each field, feature1 thru to feature4 because double glazing could be entered in any four of them.

I have this so far but, it doesnt do what i need it to do as stated above:

SELECT *
FROM propertyforsale
WHERE $searchlocation LIKE '%$location[$j]%'
AND NoBedrooms>= $minbed
AND Price>$minprice AND Price<$maxprice
AND(Feature1 = '$features1' OR Feature1 = '$features2' OR Feature1='$features3' OR Feature1='$features4')
OR (Feature2 = '$features1' OR Feature2 = '$features2' OR Feature2='$features3' OR Feature2='$features4')
OR (Feature3 = '$features1' OR Feature3 = '$features2' OR Feature3='$features3' OR Feature3='$features4')
OR (Feature4 = '$features1' OR Feature4 = '$features2' OR Feature4='$features3' OR Feature4='$features4')
ORDER BY $sortby ASC&quot;;


What the above SQL returns is too many results, it checks double glazing against the database and returns the ones with double glazing in any of the fields features1 to features4 BUT it then gives me more results

dont know what to do

any help is much appreciated

thanks in advance

anymore info dont hesitate to ask

thanks ppl

sanj










i am writing a select statement that will select all those entries with a certain keyword.

This keyword has to be checked with all 4 fields, i.e. features1 thru to 4

 
Hi THERE SORRY PPL Im such a dumb ass the Select statement was correct it did return what i wanted.. well at least i think it did.... ehhee

cheers anyway.. if u think im wrong and u think the select statement should be different please feel free to comment as the most efficient way is always the best way

thanks ppl

 
You need some extra parenthesis to get the right precedence.

Code:
SELECT *
FROM propertyforsale
WHERE $searchlocation LIKE '%$location[$j]%'
AND NoBedrooms>= $minbed
AND Price>$minprice AND Price<$maxprice
AND((Feature1 = '$features1' OR Feature1 = '$features2' OR Feature1='$features3' OR Feature1='$features4')
OR (Feature2 = '$features1' OR Feature2 = '$features2' OR Feature2='$features3' OR Feature2='$features4')
OR (Feature3 = '$features1' OR Feature3 = '$features2' OR Feature3='$features3' OR Feature3='$features4')
OR (Feature4 = '$features1' OR Feature4 = '$features2' OR Feature4='$features3' OR Feature4='$features4'))
ORDER BY $sortby ASC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top