讨论一个sql

taoistong 2011-01-19 11:01:49

select * from optionInfo a
,(********) b
where a.OptionID=b.OptionID

注:上面******** 是一个子查询。 返回一列
当select * 的时候没有问题, 不过我改成select a.*就会出现查询超时
大家看看有么有遇到这种情况? 或者知道是什么原因造成的

...全文
104 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gogodiy 2011-01-20
  • 打赏
  • 举报
回复
关注下,这个情况还真没遇到过。
UPC子夜 2011-01-19
  • 打赏
  • 举报
回复
select * 是查的a和b所有的列 而select a.*只查询了a中的列 只会变快 不会变慢 楼主仔细确认一下
我感觉 很多觉得不可能发生的事情 最终原因都是有些地方疏漏了
andysun88 2011-01-19
  • 打赏
  • 举报
回复

if object_id('tt') is not null
drop table tt
if object_id('tb') is not null
drop table tb
go
Create table tt(id int,Num decimal(15,5))
Create table tb(id int,Num decimal(15,5),pID int)
go
insert into tt
select 1,0 union all
select 2,0 union all
select 3,0 union all
select 4,4
insert into tb
select 1,0,1 union all
select 2,0,1 union all
select 3,0,1 union all
select 4,4,1
go
select a.* from tb a ,(select top 1 id from tt) b
where a.pID= b.id

select * from tb a ,(select top 1 id from tt) b
where a.pID= b.id

--感觉没有区别啊

sadikaqy 2011-01-19
  • 打赏
  • 举报
回复
试试这个

select a.* from optionInfo a
left join (********) b
on a.OptionID=b.OptionID
andysun88 2011-01-19
  • 打赏
  • 举报
回复
你的a 表的数据多少笔?
哇咔咔 2011-01-19
  • 打赏
  • 举报
回复
这样的语句经常用,怎么会有问题
中国风 2011-01-19
  • 打赏
  • 举报
回复
当select * 的时候没有问题, 不过我改成select a.*就会出现查询超时?

------------
應該不會出現樓主的情況,樓主選中語句查看執行計劃
taoistong 2011-01-19
  • 打赏
  • 举报
回复

试了一下, 都一样

[Quote=引用 1 楼 qianjin036a 的回复:]
试试

SQL code

select a.* from optionInfo a
inner join (********) b
on a.OptionID=b.OptionID
[/Quote]
gw6328 2011-01-19
  • 打赏
  • 举报
回复
不应该
-晴天 2011-01-19
  • 打赏
  • 举报
回复
试试

select a.* from optionInfo a
inner join (********) b
on a.OptionID=b.OptionID
dawugui 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用楼主 taoistong 的回复:]
select * from optionInfo a
,(********) b
where a.OptionID=b.OptionID

注:上面******** 是一个子查询。 返回一列
当select * 的时候没有问题, 不过我改成select a.*就会出现查询超时
大家看看有么有遇到这种情况? 或者知道是什么原因造成的
[/Quote]
语句没错,建议对OptionID建立索引.

34,593

社区成员

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

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