Jhon So Jhon So - 2 years ago 61
SQL Question

Query 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 a 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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download