dtds8802 2012-05-14 06:27
浏览 34
已采纳

Mysql关节是可能的吗?

I have two table one table containing station id and station name, and another table containing id, name, startStationId, endStationId. I know second table's id by using that id i need to fetch all details of second table with station name for corresponding startStationId, endStationId.

ex: table1
---------------------------------
slNo staionId staionName
---------------------------------
1     0012     Bangalore ,
2     0014     Chennai ,
3     0015     Mumbai
---------------------------------

Table 2:
------------------------------------------
Id   Name    startStationId   endStationId
-------------------------------------------
123  Dhinesh   0014             0015
-------------------------------------------

For example i know second table id(123).. so i want to fetch all results by using id, result would be.

Id =>123, Name => Dhinesh, StartStaion =>Chennai , Endstation=>Mumbai.

How can we write in one single query...?

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • dsbowmvth16379079 2012-05-14 06:33
    关注

    Try this.

    SELECT t2.Id,t2.name,t1.StationName,t3.StationName
    FROM table2 t2
    INNER JOIN table1 t1 ON t2.startStationId = t1.stationId
    INNER JOIN table1 t3 ON t2.endStationId = t3.stationId
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题