表 a       id  

2   
表 baid   content
1      asss   
1        sf
2       示范法
2       不被
联查后得到
id    content
1      asss
null   sf
2       示范法
null    不被
就是id相同的给值空

解决方案 »

  1.   

    可以用SQL语句实现,但极不建议如此做法。这种功能应该是在你的程序页面处理中来实现。mysql> select * from a;
    +------+
    | id   |
    +------+
    |    1 |
    |    2 |
    +------+
    2 rows in set (0.00 sec)mysql> select * from b;
    +------+---------+
    | aid  | content |
    +------+---------+
    |    1 | asss    |
    |    1 | sf      |
    |    2 | 示范法  |
    |    2 | 不被    |
    +------+---------+
    4 rows in set (0.00 sec)mysql> select
        ->  case when
        ->          (select count(*) from b where aid=t.aid and content<t.content)=0    ->          then a.id end as id,
        ->  t.content
        -> from a inner join b t on a.id=t.aid;
    +------+---------+
    | id   | content |
    +------+---------+
    |    1 | asss    |
    | NULL | sf      |
    |    2 | 示范法  |
    | NULL | 不被    |
    +------+---------+
    4 rows in set (0.00 sec)mysql>
      

  2.   

    content<t.content 何解啊 大师
      

  3.   

    加入自增字段ID
    SELECT iif(ma is not null,null,a.aid),a.content from tt4 a left join (select aid,max(id) as ma from tt4 group by aid) b
    on a.aid=b.aid and a.id=b.ma