0

I am trying to get results from other table using LEFT JOIN. I want to show user location using Join.

My database looks like this:

User table:

#ID   |  location_id | email | pass
------------------------------------
  1   |   1          | ...    | ....

Locataion table:

#ID   |  county_id   | city_id | user_id
------------------------------------------
  1   |   1          |  1      |    2

Coutnries table:

#ID   |  name     |  
-------------------
  1   |  Usa
  2   |  Belgium
  3   |  Serbia

Cities table:

 #ID   |  name     |  
-------------------
  1   |  Berlin
  2   |  London
  3   |  New Your
Dharman
  • 30,962
  • 25
  • 85
  • 135
Ivan
  • 5,139
  • 11
  • 53
  • 86
  • 1
    what is your expected output? have you tried anything at all? – Vamsi Prabhala Oct 23 '15 at 13:30
  • 2
    Possible duplicate of [Join two mysql tables with php](http://stackoverflow.com/questions/10172411/join-two-mysql-tables-with-php) – Drenmi Oct 23 '15 at 13:34
  • I really hope that's a typo in the `coutnries` and not the real table name. Otherwise you will annoy developers and those that maintain this table for years to come. Same for `Locataion` – xQbert Oct 23 '15 at 13:42

1 Answers1

1

Try this way

select * from usertable as a
join locataion as b on a.location_id=b.id
left join Coutnries as c on b.County_id = c.id
left join cities as d on b.City_id= d.id
Mukesh Kalgude
  • 4,814
  • 2
  • 17
  • 32