dsa4d4789789 2016-11-10 13: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 14: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部