douying1119 2011-04-05 21:55
浏览 26
已采纳

用于ExtJS网格的MySQL UNION ALL - 需要唯一的id列

I am using an ExtJS 3.0 grid and generate data from PHP using MySQL. I have setup my idProperty of the grid on the id column. The problem is that I have 2 tables for incoming invoices and one for outgoing invoices with same columns. I want to make a UNION ALL on these 2 tables and show the result into the ExtJS grid. The problem is that there are some duplicate id's coming out from these tables that causes the ExtJS grid to skip them rows. I know I can do simple UNION to skip duplicates but I need every row in the grid, even if they have the same id. There are actually no distinct data that I can relate to.

Any ideas ? Thanks.

  • 写回答

2条回答

  • douyi3632 2011-04-06 15:32
    关注

    Why not add some prefix to the id-column when SELECTing the data:

    (SELECT CONCAT('in-', id) AS id, ... FROM in_table)
    UNION ALL
    (SELECT CONCAT('out-', id) AS id, ... FROM out_table)
    

    You'll have to make sure that the field-definition for the id-field in your reader configuration has the correct type (auto or string in this case).

    If you need the real id afterwards, change the query to select the real id as well:

    (SELECT CONCAT('in-', id) AS gid, id, 'in' AS type ... FROM in_table)
    UNION ALL
    (SELECT CONCAT('out-', id) AS gid, id, 'out' AS type, ... FROM out_table)
    

    Your idProperty will be gid now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况