vendredi 23 octobre 2015

How to get node content based on sibling content from xml column in database?

<book>
 <author>a1</author>
 <title>t1</title>
</book>
<book>
 <author>a1</author>
 <title>t2</title>
</book>
<book>
 <author>a2</author>
 <title>t3</title>
</book>
<book>
 <author>a3</author>
 <title>t4</title>
</book>

I want to get all titles and only titles of books by an author. The book info is stored in a db column as xml data. Each is in a different row. I tried various value calls and it didn't work at all. The closest I got was:

select parameters.query('//book[author="a1"]/title/text()') from tablename

But this returns 4 rows with

"t1"
"t2"
""
""

Please help

Aucun commentaire:

Enregistrer un commentaire