I'm having a table for users and a table for orders and a table for cities names which is cities_translation. In users table I have user id, first name, lastname, city id and representative id. The representative is just another user in the same table. what I want to do is to join these tables to get a table like this
user id first name last name city name representative wholesaler
1 foo bar city1 2 yes
2 user user city2 0 no
The expected result is
user id first name last name order id city name representative
1 foo bar 1 city1 user
Query:
Select
orders.id, orders.user_id, orders.total, orders.final_total, orders.order_status_id,
orders.unix_time, u.id,u.email, u.first_name, u.last_name,m.first_name as rep_firstname,
m.last_name as rep_lastname, u.representative_id,u.city_id,cities_translation.*
From orders,cities_translation,users u
left join cities_translation
Where u.city_id = cities_translation.city_id
And orders.user_id = u.id
And cities_translation.lang_id='2'
And orders.order_status_id='1'
Left join users r on u.representative_id = r.id
Group by orders.user_id
Limit 5
But the result is: "#1066 - Not unique table/alias: 'cities_translation'" So how to rewrite this query to avoid this error and get representative name of each wholesaler