dsa4d4789789 2016-11-10 21:03
浏览 49
已采纳

如何从laravel中的两个表中选择行并将它们作为单个列表返回

I have two tables,one is called patient_payments and the other is patient_billing.i now want to select all the rows from each table and then present them as a single list in my webpage.I am using laravel framework and i have used raw query as follows

$items = DB::select(DB::raw('select * from patient_payments pp,patient_billings pb'));

One table has three rows and the other five rows and i was expecting two get eight rows but the query returns 14 rows which is wrong.Any idea what is wrong with my query is much appreciated.

Thanks in advance

  • 写回答

1条回答 默认 最新

  • dougong1031 2016-11-10 22:00
    关注

    If both tables have the same number of columns, you can use union() method like this:

    $items = DB::table('patient_payments')
        ->union(DB::table('patient_billings'))
        ->get();
    

    Read more about Laravel Query Builder: union() here.

    Hope this help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器