douping5015 2016-03-21 17:14
浏览 90
已采纳

json可以包含相同的键值吗?

I take the content of two table performing a join like this:

SELECT * FROM table1
     INNER JOIN table2
     ON table1.code = table2.code

Now the table1 have a structure like this:

|CODE|Info|Created          |Modified
|R789|Home|21/03/2016 10:00 |21/03/2016 15:00

and table2:

|CODE|Description|Created       |Modified
|R789|Testing| 21/03/2016 10:05 | 21/03/2016  18:10

Now the problem is that the query return this result:

"Code":"RB01",
"Info":Home,
"Created":"21/03/2016 10:05",
"Modified":"21/03/2016 18:10",
"Description":"Testing"

How you can see I have createdand modified that is identical in the two tables. So the query discard the created and modified of table1.. this is a problem for me, how can I avoid this situation?

  • 写回答

1条回答 默认 最新

  • dru5089 2016-03-21 17:18
    关注

    You need to use the AS keyword to create an alias for the column name. Consider this:

    SELECT t1.CODE, t1.Info, t1.Created AS t1Created, t1.Modified AS t1Modified, t2.Description, t2.Created AS t2Created, t2.Modified AS t2Modified
        FROM table1 t1
        INNER JOIN table2 t2 ON t1.CODE = t2.CODE
    

    This will return

    "Code":"RB01",
    "Info":Home,
    "t1Created":"21/03/2016 10:00",
    "t1Modified":"21/03/2016 15:00",
    "Description":"Testing",
    "t2Created":"21/03/2016 10:05",
    "t2Modified":"21/03/2016 18:10",
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端