Complex SQL Query to get data from multiple tables in sequence

Viewed 21

I am stuck in writing query for my system. Scenario is:

I have a database with Employees, Companies,EmployeesCompanies, Countries, States and Cities Table with given columns
Employee Table
id - name - country_id - state_id - city_id

Companies Table
comp_id - company_name

EmployeesCompanies
id - employee_id(FK) - comp_id (FK)

Countries
c_id - country_name

States 
state_id - state_name - state_country(FK)

Cities
city_id - city_name - city_state(FK)

My Desired Query/Output

I want all the countries with their states and states with their cities and cities with their employees and employee with their companies

Note each country have multiple states and each states have multiple cities and each city have multiple employees and each employee have multiple companies

Any help will be appreciated!

0 Answers
Related