I don't think that what you're asking for is reasonably possible. This would lead to several problems: - how the client side knows which columns are fetched from which row - what if id X in table has 3 rows in table B, but id Y has two rows, what would be the result etc I would look for alternative solutions for the client side. If the client needs the data in several (undetermine amount) columns based on several rows, fetching the data in such format from the database isn't practical. Could you for example use XML formatting for the data from the database and then use XML data at client or should you fetch the correct rows from the database as they are and handle all the formatting at the client. The correct approach depends on the requirements, what is the client side actually doing.
The need to optimize rises from a bad design. My articles[^]