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条)

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名