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%'请问要达到以上效果,第二个子查询要怎么替换代码会简短点
select scan_id,username from t_image a inner join t_user t on a.operator=t.id where t.username like '%b%'
select scan_id,username from t_image a inner join t_user t on a.operator=t.id where t.username like '%b%'
select scan_id,(select username from T_USER where id=a.operator and username Like '%b%') from T_IMAGE a
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%'
如果你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%'
select a.scan_id, t.username from T_IMAGE a , T_USER t where a.id=t.operator and t.username Like '%b%'
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 ??
--内连接哈 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%'
select a.scan_id,b.username from t_image a,t_user b where a.operator = b.id and a.operator like '%b%'
select scan_id,username from T_Image inner join T_User on operator=id where username like '%b%'
from t_image a inner join t_user t
on a.operator=t.id
where t.username like '%b%'
from t_image a inner join t_user t
on a.operator=t.id
where t.username like '%b%'
T_IMAGE a
a.scan_id,b.username
from
T_IMAGE a
inner join
T_USER b on a.operator=b.ID
where
a.username like '%b%'
select a.scan_id,b.username from
T_IMAGE a , T_USER b
where a.operator = b.id and b.username Like '%b%'
T_IMAGE a , T_USER t where a.id=t.operator and t.username Like '%b%'
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
??
--内连接哈
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%'
from t_image a,t_user b
where a.operator = b.id
and a.operator like '%b%'
select scan_id,username from T_Image inner join T_User on operator=id where username like '%b%'