Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Where vs Having

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2004-11-23 : 14:38:57
Hi friends
which one of the following is ideas/better

1) select * from authors where authid='12'

2) select * from authors having authid='12'

I believe first one is faster but i noticed one of senior collegues using lot sql stmts like the 2nd one.

Any ideas

Cheers

nr
SQLTeam MVY

12543 Posts

Posted - 2004-11-23 : 14:41:16
select * from authors where authid='12'

The second probably comes from access and is very poor.
Should only use having with a group by and only for agregates.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2004-11-23 : 14:42:34
You only need to use having when your using a group by clause (for example, having COUNT(*) > 1). You should try to use the where clause whenever you can over the having clause.

Dustin Michaels
Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2004-11-23 : 14:43:58
Thanks for quick replies nr and Dustin.
I just wondered why our senior colleagues uses that way.
Thanks once again

Cheers
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-11-23 : 14:52:02
quote:
[i]but i noticed one of senior collegues using lot sql stmts like the 2nd one.



Not in SQL Server you didn't.

That would throw an error



Brett

8-)
Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2004-11-23 : 14:53:50
ha..ha.. u r right Brett
we use visual foxpro !!
Thanks

Cheers
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-26 : 02:43:28
"You should try to use the where clause whenever you can over the having clause"

And SQL Server will convert HAVING into WHERE whenever IT can!

Kristen
Go to Top of Page
   

- Advertisement -