really need it like this:
<maintable mainid="15">
<subtable1 subid="91" mainID="15" />
<subtable1 subid="92" mainID="15" />
<subtable2 subid="104" mainID="15" />
<subtable2 subid="162" mainID="15" />
</maintable>
Main Topics
Browse All TopicsI am having some trouble with nested inner joins
Here is the query that doesn't work properly:
SELECT
maintable.*,
subtable1.*,
subtable2.*
FROM
maintable
INNER JOIN
subtable1 ON maintable.mainid = subtable1.mainID
INNER JOIN
subtable2 ON maintable.mainid = subtable2.mainID
WHERE
maintable.id = 15
FOR XML AUTO
The current results are:
<maintable mainid="15">
<subtable1 subid="91" mainID="15">
<subtable2 subid="104" mainID="15" />
</subtable1>
<subtable1 subid="92" mainID="15">
<subtable2 subid="162" mainID="15" />
</subtable1>
</maintable>
My desired results are:
<maintable mainid="15">
<subtable1 subid="91" mainID="15" />
<subtable1 subid="92" mainID="15" />
<subtable2 subid="104" mainID="15" />
<subtable2 subid="162" mainID="15" />
</maintable>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
First of all, since subids are included in the maintable there is no need for the Inner Joins. But I suspect you are attempting to expand the XML once you get the correct format.
If you can use For XML Explicit instead of For XML Auto, I can post the query.
In the meantime you may also, want to maintain your open questions:
DTS Import Date: 02/21/2002 03:26AM PST
http://www.experts-exchang
DTS package Date: 02/07/2002 07:23AM PST
http://www.experts-exchang
port VBscript Encrypt function to javascript Date: 02/11/2002 11:04PM PST
http://www.experts-exchang
auto detection of email client Date: 09/09/2001 10:17PM PST
http://www.experts-exchang
Thanks,
Anthony
I have achieved this output via XML Explicit ... but am interestedin getting the following output using XML Auto .. if possible
<maintable mainid="15">
<subtable1 subid="91" mainID="15" />
<subtable1 subid="92" mainID="15" />
<subtable2 subid="104" mainID="15" />
<subtable2 subid="162" mainID="15" />
</maintable>
greenrc:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2002-05-23 at 23:14:21ID: 7031288
Try this:
SELECT
*
FROM
maintable
INNER JOIN (
SELECT 1 as sub, * FROM subtable1
UNION ALL
SELECT 2 as sub * FROM subtable2
) as subtable
ON maintable.mainid = subtable.mainID
WHERE
maintable.id = 15
FOR XML AUTO
should give something like this:
<maintable mainid="15">
<subtable sub="1" subid="91" mainID="15" />
<subtable sub="1" subid="92" mainID="15" />
<subtable sub="2" subid="104" mainID="15" />
<subtable sub="2" subid="162" mainID="15" />
</maintable>
Hope this helps