【问题标题】:MySQL: highlight rows in table1 that cannot a found on table2 [closed]MySQL:突出显示 table1 中无法在 table2 上找到的行 [关闭]
【发布时间】:2013-12-16 02:26:35
【问题描述】:

比方说……

表1

id   amount    ref#
1    100.00    123
2    150.00    524
3    200.00    569

表2

id   name   ref#
1    john   123
2    alex   524
3    rich   568
4    rico   685
5    toby   456
6    rick   258

现在我想查看 Table1 中的所有记录,并突出显示 Table1 中的 ref# 在 Table2 ref# 中找不到的行。所以 jtable 中的结果应该是..

id   amount    ref#
1    100.00    123
2    150.00    524
3    200.00    569     <-- being highlighted

【问题讨论】:

    标签: java mysql jtable


    【解决方案1】:

    如果你做一个连接来比较你的表,例如:

    SELECT id, amount, a.ref, b.ref
    FROM table1 a 
    LEFT JOIN table2 b on a.ref = b.ref
    

    然后您可以使用结果 where b.ref == null 突出显示 table1 中存在但 table2 中不存在的任何结果。如果b.ref != null 表示两个表都有结果。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多