tags:

views:

30

answers:

1

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 from countries table

How can i get that?

A: 

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.

Kyra
I have 7580 rows in holi table and i tried the following query but it listed 7638 rows.. I dont know where i'm doing wrong the query is select holiday_countries.id , year(holi.hdate), holi.hdate from holi left join holidays on holi.description = holidays.holiday left join countries on holi.country=countries.name left join holiday_countries on holidays.id = holiday_countries.holiday_id and countries.id = holiday_countries.country_id
Clewon
Maybe try a left join instead of a join. Right now it would be generating every possible combination.
Kyra
Look at the above comment, its a left join only
Clewon