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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching 2 db fields

Status
Not open for further replies.

bellmd

Programmer
Sep 28, 2000
15
0
0
GB
I'm trying to search two fields in a database. The SQL statement below returns all the records in the database:

Code:
select * from table where (desc OR title LIKE "%this%") AND (desc OR title LIKE "%that%")
 
bellmd,

Is that syntax definitely vaid?

Does it work if you change it to the following:

select * from table where (desc LIKE '%this%' OR title LIKE '%this%') AND (desc LIKE '%that%' OR title LIKE '%that%')
Mise Le Meas,

Mighty :)
 
Yes, the syntax is correct. That is what I am currently using, and it works well. The main problem is that not all the records have a description, because some have sufficient information in the title, and without serching the titles also some of the record will not show up in through the search.
 
What SQL database are you using..

desc OR title LIKE "%that%" isn't valid ANSI sql

you should do as Mighty suggested and use the correct SQL syntax..

I think the reason your query is returning all records because it is looking at (desc OR title LIKE "%that%") to mean ([DESC IS NOT EMPTY] OR TITLE LIKE "%that%")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top