doubu7134 2012-10-10 01:06
浏览 23

如何从带有连接的查询中按结果集?

I have a domain model and a data mapper built with PHP and MySql. Some domain objects appear only in the context of others and in these cases I am using dependent mappings, i.e. the dependent objects do not have their own mapper, but are instead persisted by their owner's mapper.

For performance reasons I am joining multiple tables and issuing one SQL query, (rather than one query per table), and this is where the difficulty arises: the results of my queries are cartesian joins (of course) and will require a fair amount of array sifting to get sensible data with which to populate domain objects.

For example, I have three tables: one parent (P1) and two children (C1 and C2). If a single record in P1 has two records in both C1 and C2, I have four records in my result set. I can cycle through the result set array looking for unique values and create a fresh array from these, but that seems like a lot of work.

This is bound to be a common problem. What is the typical way to solve it? I looked through the SPL data structures and iterators but didn't find anything useful. I don't want to split into multiple queries unless I really have to.

Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?