0

I am trying to get all titles that contain a certain word from my database in XQuery in SQL I would use WHERE title LIKE '%England%' - I am wondering how to do this in XQuery?

My XQuery query looks like this:

(:Selects document:)
for $x in doc ("tmdb_5000_movies(1).xml")/movies/movie 
(: :)
where $x/title (:NOT SURE WHAT TO PUT HERE:)
(:0:)
return $x/ *
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
BradleighJL
  • 43
  • 1
  • 8
  • Does this line of code do the same as like? for $x in doc ("tmdb_5000_movies(1).xml")/movies/movie [matches(title, '.*England')] (:0:) return $x/ * – BradleighJL Nov 29 '19 at 16:07

2 Answers2

1

This does it.

for $x in doc ("tmdb_5000_movies(1).xml")/movies/movie [matches(title, '.*England')] 

return $x/ *

Much prefer SQL, However, I can see why this is the future

BradleighJL
  • 43
  • 1
  • 8
1

I have no SQL DB to test with at hand but

doc("movies.xml")//movie[matches(title, '^.*England.*$')]/*

does work in other xquery runtimes. You should test, if you need the FLOWR-expression.

The regular expression @BradleighJL uses in his answer could be faster (.*England) and should also match all the cases. I just wanted to make a distinction between just "%England" ('^.*England$') and %England%.

line-o
  • 1,885
  • 3
  • 16
  • 33