samedi 18 juin 2016

Laravel: Query Builder Join Multi Tables

I have 3 tables:

users_tb with columns:

user_id (pk)
user_name

device_tb with columns:

user_id (fk)
device_id (pk)
device_name

part_tb with columns:

deive_id (fk)
part_id (pk)
part_name
user_buy (fk)

Relationship:

device_tb one to many part_tb (1 device can create from to many part)

user_tb one to many device_tb (1 people can create to many device)

user_tb one to many part_tb (1 people can buy to many device)

How i can count the total parts used for all device per user?

Example: device: PC1 - created from parts: mouse, keyboard, cpu - by user: Allen

Result: User Allen used 3 parts

I'm so sorry about my English :((



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire