我的数据库中有以下表格:
表格顺序
|------------------------------------------------------|
| Id | uid | order | price | City_to_be_update
|------------------------------------------------------|
| 1 | 25 | someFoods | 10025 |
|------------------------------------------------------|
| 2 | 30 |Some veggies| 2015|
|------------------------------------------------------|
| 3 | 12 |Milk | 145 |
|------------------------------------------------------|
表用户:
|------------------------------------------------|
| Id | uid | city_id | Address|
|------------------------------------------------|
| 1 | 30 | 1 | myAddress |
|------------------------------------------------|
| 2 | 12 | 2 | Asdfads |
|------------------------------------------------|
| .... | .. | .. | ....... |
|------------------------------------------------|
表城:
|------------------------------------------------|
| Id |city_id| city_name | Country|
|------------------------------------------------|
| 1 | 2 | Abc | Uae |
|------------------------------------------------|
| 2 | 3 | Def | Ghi |
|------------------------------------------------|
| .... | .. | .. | ....... |
|------------------------------------------------|
我想做的是
Select * from `order`
$user_id [ uid ];
Select * from `users` where `uid` = ‘$user_id’;
$city_id [ city_id ];
从city
中选择*,其中city_id
='$ city_id';
$ city_name [city_name];
最后想要更新订单表,如下所示
Update `order` SET ` City_to_be_update`= $city_name’;
如何做到这一点,任何人都可以帮助我吗?
答案 0 :(得分:2)
使用联接尝试此查询,
UPDATE
< OrderTable > AS a LEFT JOIN < UsersTable > AS b ON a.uid=b.uid
LEFT JOIN < CityTable > AS c ON b.city_id=c.city_id
SET
a.City_to_be_update=c.city_name