Reputation: 83
I have a search function were I can find Address Line 1 in my database, but I was wondering if it is possible to find addressline 1,2,3,4,5 which are all separate attributes on the same line, depending what the user searches for. See code below. Any help would be appreciated, Thanks.
This Works:
<sql:query var ="NameCheck" scope = "session" dataSource = "${bookdB}">
SELECT * FROM Company
WHERE Address_1 LIKE ?
<sql:param value = "%${param.category}%" />
</sql:query>
Is this possible in some form of syntax (either '||', 'OR' operator).
SELECT * FROM Company
WHERE Address_1 OR Address_2 OR Address_3 OR Address_4 OR Address_5 LIKE ?
Upvotes: 0
Views: 1157
Reputation: 15860
In Sql, yes you can use OR
instead of ||
, however this is the only way to select the rows in conditions, but you must complete each and every condition and then start a new condition like this:
SELECT * FROM Company
WHERE Address_1 LIKE
OR Address_2 LIKE %a OR
Address_3 LIKE %a OR
Address_4 LIKE%a OR
Address_5 LIKE %a
Computer won't change its algorithm, so you should stick to its language :)
To search multiple addresses you can use AND
and then write them in the HTML. You can use OR
when one condition is not true, then move to the next one. This way, you must close the condition before OR
operator.
http://www.w3schools.com/sql/sql_and_or.asp
Upvotes: 1
Reputation: 16351
The syntax you use is not correct.
You'll have to do something like :
SELECT * FROM Company
WHERE Address_1 LIKE ...
OR Address_2 LIKE ...
OR Address_3 LIKE ...
OR Address_4 LIKE ...
OR Address_5 LIKE ...
Upvotes: 1