5 pts.
 SQL related tables
I have 2 tables one with all my products and their accociated details and another with comments on the products. Product table 1 prodID, title, description, price Comments table 2 commID, prodID, comment I would like to export this to a single XML file, thus an XML element for each product from table 1 with all its comments in table 2 as child nodes within the product emelement: <prods> <prod> <title></title> <description></description> <price></price> <comments> <comment></comment> <comment></comment> <comment></comment> </comments> </prod> </prods> I've tried a JOIN statement, but that returns a product row for each comment. What is the correct SQL SELECT to return one product row with all its comment rows? Thanks...  

Software/Hardware used:
MySQL5+, PHP5+
ASKED: October 16, 2009  7:10 AM
UPDATED: October 19, 2009  8:26 PM

Answer Wiki:
I do not know about putting in the XML tags - I know some version of DB2 will do it. But ignoring the XML, I see two different ways to get the data. 1) are you in a program? if so, open a cursor against product table and for every row open a cursor against co0mments table and process the rows accordingly. 2) are you trying to do this in one SQL statement? then something like this will return your data columns (but again I am skipping the XML tags) SELECT T1.PRODID, T1.DESCRIPTION, 0 FROM PRODUCT TABLE T1 UNION SELECT T2.PRODID, T2.COMMENT, T2.COMMID FROM COMMENTTABLE T2 ORDER BY 1,3
Last Wiki Answer Submitted:  October 19, 2009  8:26 pm  by  Meandyou   5,205 pts.
All Answer Wiki Contributors:  Meandyou   5,205 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _