XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
John  TowersSubject: XQuery beginner problem
Author: John Towers
Date: 09 Mar 2007 09:02 AM
Originally Posted: 09 Mar 2007 08:39 AM
Hi guys, I'm a beginner at XQuery and I'm coming at it from a relational SQL perspective, and I think it's tripping me up. I'm trying to use the following query, to retrieve all the titles of books that have a publication date of 1959 or 1939, and the ratings of all movies where the directors go by Michel Gondry or Edgar Wright:

for $book in //book
for $film in //film
where ($book/yearofPublication = '1959'
or $book/yearofPublication = '1932')
and ($film/director = 'Michel Gondry'
or $film/director = 'Edgar Wright')
return ($book/ title, $film/ rating)


In my application the above query is returning the following results

<result>Naked Lunch</result>
<result>PG</result>
<result>Naked Lunch</result>
<result>15</result>
<result>Brave New World</result>
<result>PG</result>
<result>Brave New World</result>
<result>15</result>
<result>Brave New World</result>
<result>PG</result>
<result>Brave New World</result>
<result>15</result>

The problem is the repetition, I'm getting results returned for each iteration through the XML? Can anyone show me how I can re-write this query to get the results I'm after, while also getting rid of that repetition? I understand that the results I am getting are caused by returning values based on the two 'for' iterations through the tree, but can't figure out how to fix it so that the relevant values are only returned once.

Thanks a lot, any help would be great.

- John

Posttop
Tony LavinioSubject: XQuery beginner problem
Author: Tony Lavinio
Date: 09 Mar 2007 02:58 PM
Where is your join?
You're producing the cross product join - every row to every row.

(It would be easier to help also if we saw the sample XML)

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.