2

I need to find a way to get the ids starting with 11, in sql is with 'start with' and 'Connect by prior' but in HQL, how can I do that?, if there is a better way in grails, the help would be great, thanks!

(Updated: Sorry, I didn't write the other command which is: 'connect by prior')

user1698253
  • 55
  • 1
  • 7

3 Answers3

4

Assuming the ID is a string, why not simply use a like clause:

where id like '11%'

Assuming it's not a string, you could cast it to a string:

where cast(id as STRING) like '11%'

or

where str(id) like '11%'
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

If you mean query for records with ids greater or equal to 11, then example if you have a table of Books, then the HQL would be

def books = Books.executeQuery("SELECT b from Books b WHERE id >= 11")
ibaralf
  • 12,218
  • 5
  • 47
  • 69
0

Recursive SQL queries are non-standard so HQL does not support them (although I found a paper that appears to propose and prototype adding support). To do them you'll need to stick with SQL. Here's a similar question.

Community
  • 1
  • 1
doelleri
  • 19,232
  • 5
  • 61
  • 65