首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

select * from (select top 1 a from A) a,(select top 1 b from B where xx='xx') b的

2012-02-17 
select * from (select top 1 a from A) a,(select top 1 b from B where xxxx) b的问题1select*from(s

select * from (select top 1 a from A) a,(select top 1 b from B where xx='xx') b的问题
1   select   *   from   (select   top   1   a   from   A)   a,(select   top   1   b   from   B   where   xx= 'xx ')   b    
a           b
1           2      
(select   top   1   a   from   A)   a   总有记录
(select   top   1   b   from   B   where   xx= 'xx ')   b    
    它如果没有记录的话,语句1也不出来记录,,这是咋回事泥

[解决办法]
帮顶
[解决办法]
语句1是用的迪卡尔积,需要两个表都有数据才行.
[解决办法]
帮顶

[解决办法]
where xx= 'xx '--条件不满足没记录
[解决办法]
(select top 1 b from B where xx= 'xx ') b
它如果没有记录的话,语句1也不出来记录,,这是咋回事泥
----------------------
现在说的是上述查询没有结果时第一个语句也没有结果的问题.
[解决办法]
从2个表中提取数据吗?
要是从2个表里提取数据,需要有一个记录关联项?

(SQL不会,如果错了,就当作没看见好了)
[解决办法]
select top 1 a from A--只要表里有记录都满足
[解决办法]
因为这个语句是内连接,所以如果b没有记录就不会出来记录

要达到b没记录也能出来记录,可以这样做:
select * from (select top 1 a from A) a
left outer join (select top 1 b from B where xx= 'xx ') b
[解决办法]
用左连试一试。
[解决办法]
对不起,上面语句错误:
正确应该的是:
select * from (select top 1 a from A) a
left outer join (select top 1 b from B where xx= 'xx ') b
on 1= 1

热点排行