如何编写另一个表项的id并自动将其与文本相等 [英] How to write an id of an item of another table and automatically equal it to the text

查看:64
本文介绍了如何编写另一个表项的id并自动将其与文本相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题搞砸了我知道:D

i有一个名为city的表,有两列,城市ID和城市名称

现在我有另一个表格中包含三列,id,时间和城市ID的航班

i在城市表中有一项,id = 1,城市名称= slemani,

现在我打开航班表和写id = 1,时间= bla bla,城市id = 1

i想自动将城市ID改为城市名,slemani id为1,我在城市id中写1 ,我想要自动更改为slemani,怎么做?



我尝试过:



i尝试使用它的id来获取文本

the title is messed up i know :D
i have a table called city , there is two columns, city id and city name
now i have another table called flights with three columns, id, time, and city id
i have an item in city table, id=1, city name= slemani,
and now i open flights table and write id=1, time=bla bla, and city id=1
i want to automatically change the city id to the city name, slemani id is 1, and i write 1 in city id, i want that 1 change to slemani automatically, how to do it?

What I have tried:

i tried to get a text using it's id

推荐答案

使用JOIN:

Use a JOIN:
SELECT f.Id, f.Time, c.CityName FROM Flights f
JOIN City c ON c.ID = f.CityId


试试这个:
SELECT f.id, f.time, c.city_name FROM flights f
JOIN city c ON c.city_id = f.city_id WHERE f.city_id=1

学习 SQL联接 [ ^ ]


这篇关于如何编写另一个表项的id并自动将其与文本相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆