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.

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

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改