Issue
How do I setup fields to be dependent on what foreign key is input?
I have googled and searched stack overflow, using similar questions to that, but couldn't find anything that fitted what I was looking for. There are pictures and an example below to better describe what I am asking.
Here's my table (that I want fields to be dependant on there foreign keys):
jo_route
is a foreign key for this table:
and jo_type
is a foreign key for this table:
When I go to insert a record into the journeys table, and select the route id. How do I get the corresponding information from that foreign keys table to appear in the respective fields in this table.
For example, jo_type
as 3 records (as shown in the picture). The foreign key jo_type
is linked with this table. Say I select the ID for air (2) in the journeys table. How do I get the related fields (jo_seats_total
) to be automatically chosen from the travel types table? So it should appear as 100.
Hopefully I have explained my problem well enough.
Thanks in advance for any help! Sorry for the long post.
Solution
I hope this is something that you looking for...
SELECT t.tt_max_seat, t.tt_name, r.ro_origin, r.ro_destination,
j.jo_seats_total, j.jo_seats_take, j.jo_seats_available
FROM journey j
JOIN route r ON j.jo_route = r.ro_id
JOIN type t ON j.jo_type = t.tt_id
WHERE j.jo_type = 2
Answered By - Naincy
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.