如题,
有两个表Tab1和Tab2,其属性字段都一样。如果,我想查询ID为1,2,3,4的数据,
且这4个数据,可能分布在上述两个表中(Tab1或Tab2)。那,我该如何来写该SQL语句呢?
可以是:
Select *
From Tab1 and Tab2
Where ID=1 or ID=2 or ID=3 or ID=4
似乎不可以~那该如何写呢?谢谢!
有两个表Tab1和Tab2,其属性字段都一样。如果,我想查询ID为1,2,3,4的数据,
且这4个数据,可能分布在上述两个表中(Tab1或Tab2)。那,我该如何来写该SQL语句呢?
可以是:
Select *
From Tab1 and Tab2
Where ID=1 or ID=2 or ID=3 or ID=4
似乎不可以~那该如何写呢?谢谢!
From Tab1
Where ID=1 or ID=2 or ID=3 or ID=4
union [all]
Select *
From Tab2
Where ID=1 or ID=2 or ID=3 or ID=4
union all
select * from Tab2 where ID=1 or ID=2 or ID=3 or ID=4
union [all]
Select * From Tab2 Where ID in (1,2,3,4)
union all
Select * From Tab2 Where ID in (1,2,3,4)
From Tab1
Where ID IN(1,2,3,4)
union [all]
Select *
From Tab2
Where ID IN(1,2,3,4)
union [all]
Select * From Tab2 Where ID in (1,2,3,4)
union [all]
Select * From Tab2 Where ID in (1,2,3,4)
Where ID in (1,2,3,4)
union all
Select * From Tab2
Where ID in (1,2,3,4)
(
select * from Tabl1
union all
select * from Tabl2
)t
where ID in (1,2,3,4)
From Tab1
Where ID=1 or ID=2 or ID=3 or ID=4
union [all]
Select *
From Tab2
Where ID=1 or ID=2 or ID=3 or ID=4
union all
Select * From Tab2 Where ID in (1,2,3,4)
union all
select * from Tab2 where ID=1 or ID=2 or ID=3 or ID=4