How to use join to fetch related data from many tables?
table name: holi
- id
- country
- hdate (holiday date)
- description
- link
and the above table is split into many tables to reduce redundancy
as table countries
- id
- name
table holidays
- id
- holiday
table holiday_countries
- id
- holiday_id (fk of id from holidays)
- country_id (fk of id from countries)
- link
SO now i need to get the hdate from table holi and id in holiday_countries
the id from holiday_conuntries can be fetched by relating the values of holi table with all the other tables..
description from holi table related to the holiday from holidays table country from holi table related to the country f开发者_运维百科rom countries table
How can i get that?
I'm not sure what exactly you are matching so this might be a bit off but I would put:
SELECT *
FROM holi
JOIN holidays AS h
ON holi.description = h.holiday
JOIN countries AS c
ON holi.country = c.name
Where the SELECT *
can be replaced with whatever you want to select.
精彩评论