ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Select Order by a specific list

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Select Order by a specific list

    Hi all,

    I'm working with sql to generate an XML,
    when I made the XMLAGG of my select (full of XmlElement) the result doesn't respect the sequence requested by my xmlschema (Obviously this sequence isn't alphabetic).
    Anyone can help me?

    many thanks.

  • #2
    It's hard to know without seeing your code, can you post it?

    But to guess, you are saying that the content of your xmlagg is not being sorted according to the 'order by' at the end of your SQL statement?
    If so then that's not surprising. The final 'order by' only refers to the order of the final output rows, and has no bearing on aggregates or subselects. However, xmlagg can contain its own 'order by' statement:
    Code:
    xmlagg(xmlelement(...),
           xmlelement(...),
           xmlelement(...)
           order by a,b,c)

    Comment

    Working...
    X