On 8/20/2010 9:30 AM, Pinaki Poddar wrote:
> 
> Try a subquery such as
> 
>         String countQuery = "select count(c) from Customer c " 
>                                     + "where exists (select a FROM Address a
> " 
>                                     +                      "where a.customer
> = c and lower(a.city) like :city)";

Excellent!  That did the trick.  I don't know if I've ever done a sub-query
before (my SQL days were long, long ago!).  My actual query is much more 
complex,
but I got it working after only ~15 tries  ;)

> One suggestion: prefer query parameters over fixed strings. Lots of
> advantages.

Agreed.  I'm doing that in many places, but probably not as many as I should.
Can you use them anywhere in a query?

For example, can:
  SELECT c from Customer c WHERE c.name LIKE :search_param
be changed to this
  SELECT c from Customer c WHERE c.:search_field LIKE :search_param
? I assumed not, but perhaps it can be?

In this example, the search-field is also specified by the user...so the field
queried will be potentially different each time.

Thanks!  I would have spent many hours discovering that on my own...
Chris

-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
[email protected]                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

Reply via email to