Jhon So Jhon So - 10 months ago 30
SQL Question

Querry with 3 tables for receive data

The idea is user can chose one line and one road and get the schedule
can someone help me with one mysql query?

I have 3 tables on my database

Example :

Table Roads

Id | RoadName
1 | StackoverflowRoad

Table Lines

Id | Linename
1 | StackoverflowLine

Table hours

HoursLineId | HoursRoadId | hours
1 | 2 | 8:35:13


you have to use inner join in order to join the 3 tables based on foreign keys.

SELECT * FROM hours 
    INNER JOIN Roads ON Roads.Id=hours.HoursRoadId 
    INNER JOIN Lines ON hours.HoursLineId=Lines.Id 
    where Roads.Id='Your ID' AND Lines.Id='Your Id';

This will get the schedule after filtering by Line Id and Road Id.