mardi 17 mars 2020

Multi table Mysql joint query in Laravel

Am trying to connect two tables Customer and Customer_Usage for getting the result.Tables are showing below.

Table: Customer

+----+-------+-------------+--------+
| id | Ip_Id | Customer_Id | Class  |
+----+-------+-------------+--------+
| 1  | 100   | A           | First  |
+----+-------+-------------+--------+
| 2  | 100   | B           | First  |
+----+-------+-------------+--------+
| 3  | 100   | C           | First  |
+----+-------+-------------+--------+
| 4  | 101   | D           | First  |
+----+-------+-------------+--------+
| 5  | 101   | E           | First  |
+----+-------+-------------+--------+
| 6  | 100   | F           | Second |
+----+-------+-------------+--------+

Table: Customer_Usage

+----+-------------+----------------+
| id | Customer_Id | Usage          |
+----+-------------+----------------+
| 1  | A           | 1245           |
+----+-------------+----------------+
| 2  | B           | 4414           |
+----+-------------+----------------+
| 3  | C           | 8521           |
+----+-------------+----------------+
| 4  | D           | 2314           |
+----+-------------+----------------+
| 5  | E           | 521            |
+----+-------------+----------------+
| 6  | F           | 5412           |
+----+-------------+----------------+

The condition is while enter a value for search Ip_Id, example for 100 it will give a result like below. How to make a joint for these two tables in Laravel using Mysql

Output result

+-------+-------------+----------------+
| Ip_Id | Customer_Id | Usage          |
+-------+-------------+----------------+
| 100   | A           | 1245           |
+-------+-------------+----------------+
| 100   | B           | 4414           |
+-------+-------------+----------------+
| 100   | C           | 8521           |
+-------+-------------+----------------+
| 100   | F           | 5412           |
+-------+-------------+----------------+

This is the query am trying.

 $result        = DB::table('Customer')
                ->where('Ip_Id','=','100')
                ->get();


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire