duanhuang2150 2015-09-04 11:53
浏览 37
已采纳

在php / mysql表中使用多个join作为对象或类似的东西

In my mysql db I have a "4 level parent table" and when I use them in php I wouldn't like to write everytime the multiple join... Example

select ... FROM tableA 
INNER JOIN tableB ON (tableA.id = tableB.idA) INNER 
JOIN tableC ON (tableB.id = tableC.idB)...
  • 写回答

2条回答 默认 最新

  • dqrnskni67375 2015-09-04 11:59
    关注

    when I use them in php I wouldn't like to write everytime the multiple join.

    Consider creating a VIEW then with your query like below and use that view in PHP code

    create view vw_multilevelquery as
    select ... FROM tableA 
    INNER JOIN tableB ON (tableA.id = tableB.idA) 
    INNER JOIN tableC ON (tableB.id = tableC.idB)...
    

    In your PHP code just perform a SELECT on created view like

    select * from vw_multilevelquery;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 输入程序运行仿真后,烟雾值不实时检测,变成固定值
  • ¥15 lingo,求错误原因,这段代码哪里不对,求帮助!
  • ¥20 数据排序,可选择排序方向
  • ¥15 修改一下代码,考虑进程到达时间不同的情况
  • ¥15 帮我看看这是个啥题,带解题过程和结果,条件如下FCF = 290471.33 g1 = 15% r = 8% g2 = 4% n = 5
  • ¥15 edem模拟颗粒不显示或者生成失败
  • ¥15 Python代码编写
  • ¥15 php 将rtmp协议转hls协议,无法播放
  • ¥20 python代码编写
  • ¥20 使用MPI广播数据遇到阻塞