Reputation: 1975
I have a SQL statement to search for an application by name.
def apps = Application.findAll("from Application as app where lower(app.name) like '%${params.query.toLowerCase()}%' ")
I want to not just be able to search by the applications name, but by different properties such as type and language. How would I add or statements to allow me to do this. Thanks!
Upvotes: 1
Views: 357
Reputation: 13056
It's not clear (to me) what framework you're using, or what specific RDBMS your database is on, but the overall thrust of SQL conditions is usually pretty simple.
Pretty much, like most other computer languages, you use and/or/not statements. Of course, in SQL you use the words, instead of (what are usually) symbols:
AND
instead of &&
OR
instead of ||
NOT
instead of !
along with the standard comparison operators:
<
, <=
, =
, <>
, >
, >=
Note that 'equals' is only a single =
sign, and 'not equals' is usually opposed angle brackets <>
.
So, given your current statement, if you wanted to only get those applications in the user's language, and exclude apps that are 'disabled', you could do something like the following:
def apps = Application.findAll("from Application as app
where lower(app.name) like '%${params.query.toLowerCase()}%'
and app.language = userLanguageParameter
and app.status <> inactiveAppStatus ");
Upvotes: 1