doulin9679 2012-07-10 19:34
浏览 130
已采纳

mySql多列连接与重合数据

I have three tables. Each one has three columns. It looks like this:

table 1                   table 2                    table 3
--------------------      --------------------       --------------------
col1    col2    colA      col1    col2    colB       col1    col2    colC
1       A       data      3       C       data       5       E       data
2       B       data      2       B       data       6       F       data
3       C       data      1       A       data       3       C       data
4       D       data      4       D       data       2       B       data
5       E       data      6       F       data       1       A       data
6       F       data      5       E       data       3       C       data

My question is if it is at all possible with JOINS to output something like this:

output table                
-----------------------------------------
col1    col2    colA       colB      colC
1       A       data       data      data
2       B       data       data      data
3       C       data       data      data
4       D       data       data      data
5       E       data       data      data
6       F       data       data      data

Note that Col1 and Col2 always have the same values in the different columns but are in different order.

I don't even know if this is possible but ideally the query would join the three tables and relate the information on col1 and col2 with each respective table and reorder the two joining tables and output a single table/array.

Let me know if this is really stupid or complex... I've been trying to wrap my head around this but by mySql knowledge is very limited.

  • 写回答

3条回答 默认 最新

  • duannai5858 2012-07-10 19:39
    关注
    SELECT *
    FROM t1
    LEFT JOIN t2 USING (col1, col2)
    LEFT JOIN t3 USING (col1, col2)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条