select  scan_id,(select username from T_USER where id=a.operator)  from
T_IMAGE a where (select username from T_USER where id=a.operator)  Like '%b%'请问要达到以上效果,第二个子查询要怎么替换代码会简短点

解决方案 »

  1.   

    select scan_id,username
    from t_image a inner join t_user t
    on a.operator=t.id
    where t.username like '%b%'
      

  2.   

    select scan_id,username
    from t_image a inner join t_user t
    on a.operator=t.id
    where t.username like '%b%'
      

  3.   

    select  scan_id,(select username from T_USER where id=a.operator and username Like '%b%')  from
    T_IMAGE a 
      

  4.   

    select 
    a.scan_id,b.username
    from 
    T_IMAGE a
    inner join
    T_USER b on a.operator=b.ID
    where
    a.username like '%b%'
      

  5.   

    如果你ID和operator一一对应.
    select a.scan_id,b.username from 
    T_IMAGE a , T_USER b 
    where a.operator = b.id and b.username Like '%b%'
      

  6.   

    select  a.scan_id, t.username   from
    T_IMAGE a , T_USER t where a.id=t.operator  and t.username Like '%b%'
      

  7.   

    declare @tb table (id int, [username] varchar(32))
    insert into @tb select username from T_USER where username Like '%b%'select scan_id, t.username
    from T_IMAGE a
    join @tb b on b.id=a.operator
    ??
      

  8.   


    --内连接哈
    select 
        a.scan_id,b.username
    from 
        T_IMAGE a
    inner join
        T_USER b on a.operator=b.ID
    where
        a.username like '%b%'
      

  9.   

    select a.scan_id,b.username
    from t_image a,t_user b
    where a.operator = b.id
    and a.operator like '%b%'
      

  10.   


    select scan_id,username from T_Image inner join T_User on operator=id where username like '%b%'