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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?