34,873
社区成员
发帖
与我相关
我的任务
分享
select * from table1 a,table2 b,table3 c where a.userid='xzy' or b.userid='xzy' or c.userid='xzy'
if object_id('table1') is not null
drop table table1
create table table1
(
userid varchar(10)
)
if object_id('table2') is not null
drop table table2
create table table2
(
userid varchar(10)
)
if object_id('table3') is not null
drop table table3
create table table3
(
userid varchar(10)
)
insert table1
select 'xzy'
insert table2
select 'abc'
insert table3
select 'ccc'
select * from table1 a,table2 b,table3 c where a.userid='xzy' or b.userid='xzy' or c.userid='xzy'
/**
userid userid userid
---------- ---------- ----------
xzy abc ccc
(所影响的行数为 1 行)
**/
select * from table1 where userid='xzy'
union all
select * from table2 where userid='xzy'
union all
select * from table3 where userid='xzy'select * from table1 a
where a.userid='xzy'
union all
select * from table2 b
where b.userid='xzy'
union all
select * from table3 c
where c.userid='xzy'select * from table1 a
where a.userid='xzy'
union all
select * from table2 b
where b.userid='xzy'
union all
select * from table3 c
c.userid='xzy'select
*
from
table1 a
full outer join
table2 b
full outer join
table3 c
where
isnull(a.userid,'')='xzy' or isnull(b.userid,'')='xzy' or isnull(c.userid,'')='xzy'like '%xzy%'可能存在的内容不够精确吧.换用LIKE的试试.