如何从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
我有两个表,一个叫做patient_payments,另一个是patient_billing.i现在想要从中选择所有行 每个表然后在我的网页中将它们作为单个列表呈现。我正在使用laravel框架,我使用了原始查询,如下所示 p>
$ items = DB :: select(DB :: raw('select * from patient_payments pp,patient_billings pb'));
code> pre>
一个表有三行,另外五行我想要两个得到 八行,但查询返回14行是错误的。任何想法我的查询有什么问题非常感谢。 p>
提前致谢 p>
div>
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.