line_state表的两个字段关联同一个外键位,我应该怎么查询才能让两个字段都能与外键关联

drop table if exists line_state;
CREATE TABLE `line_state` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fromCityId` int(11),  
`toCityId` int(11), 
`value` int(11), 
PRIMARY KEY (`id`),
foreign key(fromCityId) references city(id),
foreign key(toCityId) references city(id)
);
CREATE TABLE `city` (
`id` int(11) NOT NULL,
`name` VARCHAR(20) NOT NULL,
PRIMARY KEY (`id`)
)DEFAULT CHARSET=utf8;
select ls.id, c.name ,ls.value, ls.toCityId from line_state ls inner join city c on ls.fromCityId=c.id order by ls.id asc;

我现在的这个ls.fromCityId 可以与外键连接变成 中文字,但是ls.toCityId怎么变成中文字?

图片描述

阅读 1.3k
1 个回答
新手上路,请多包涵

select ls.id, c.name ,ls.value, ls.toCityId ,d.name from line_state ls inner join city c on

                                                                         ls.fromCityId=c.id
                                                           inner join city d on 
                                                                           ls.toCityId=d.id

order by ls.id asc;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题