两个数据库内容查询

zhmjppp 2011-07-19 10:37:23
碰到这个需求,不会
假如有两个数据库DB1 DB2
DB1有张user表
DB2有张vip表
user表

uid name isNew
1 a true
2 b true
3 c true
4 d false
....

vip表

vid uid isGold
1 3 true
2 1 false
3 2 true
3 4 true
....



现在想找出新用户(isNew)并且是黄金(isGold)VIP用户的name
...全文
83 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
--小F-- 2011-07-19
  • 打赏
  • 举报
回复
select
a.name
from
DB1..[user] a , DB2..[vip] b
where
a.uid =b.uid and a.isNew='true' and b.isGold='true'
小笨熊 2011-07-19
  • 打赏
  • 举报
回复
select tuser.name from DB1.dbo.user tuser
left join DB2.dbo.vip tvip on tuser.uid = tvip.uid
where tuser.isNew='true' and tvip.isGold='true'

如果数据很多,比如50W条,跨数据库查询会不会存在严重问题.这个还好,数据不是很多,才50W
叶子 2011-07-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhmjppp 的回复:]

如果数据很多,比如50W条,跨数据库查询会不会存在严重问题
[/Quote]

select a.* from DB1.dbo.[user] a,DB2.dbo.vip b
where a.uid=b.uid and a.isNew='true' and b.isGold='true'
--在uid字段建立索引
--50w数据不算多,没有问题
--刚才写错了,少了个连接条件,抱歉。

AcHerat 元老 2011-07-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhmjppp 的回复:]

如果数据很多,比如50W条,跨数据库查询会不会存在严重问题
[/Quote]

不会。


select a.name
from DB1.dbo.[user] a,DB2.dbo.[vip] b
where a.uid = b.uid and a.isNew='true' and b.isGold='true'
oO寒枫Oo 2011-07-19
  • 打赏
  • 举报
回复
这么少的数据 跨数据库查询 没什么问题
oO寒枫Oo 2011-07-19
  • 打赏
  • 举报
回复

select a.name
from DB1..[user] a , DB2..[vip] b
where a.uid =b.uid and a.isNew='true' and b.isGold='true'
zhmjppp 2011-07-19
  • 打赏
  • 举报
回复
如果数据很多,比如50W条,跨数据库查询会不会存在严重问题
叶子 2011-07-19
  • 打赏
  • 举报
回复

select a.* from DB1.dbo.[user] a,DB2.dbo.vip b
where a.isNew='true' and b.isGold='true'
叶子 2011-07-19
  • 打赏
  • 举报
回复
select a.*  from DB1.dbo.user a,DB2.dbo.vip b
where a.isNew='true' and b.isGold='true'

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧