Sunday, April 16, 2017

Select from 3 tables with 2 foreign keys

I have a table service which contains <PK> id and <FK> plate_number.

Then I have a table vehicles, which contains <PK> plate_number and other not important columns.

Next table is a binding table part_fix containing <FK> service_id and <FK> part_id.

Last one is part with columns id, name, `price.

I am using Laravel query builder but thats not so important now, just in case someone knows how to use it, a solution in query builder would be better for me.

I want to select from table service where I want to show in a table <PK> id, <PK> plate_number, and using the binding table, I want to assign parts for each service. I have the binding table because there was many to many relationship (one repair/service can have many parts, and also one part can be used in many repairs in autoshop).

I hope I explained this good enough, if not please ask.



via Ady96

Advertisement