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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-04-27 : 08:03:04
|
| TonyG writes "Using SQL Server 2000, the query below returns 2 random records for me. However, on occasion, the 2 records returned are identical. Does anybody have any thought for preventing this from happening?SELECT TOP 2 P.*, C.CatID FROM JEP_tblProducts P, JEP_LtblProductCategories C WHERE P.Image1<>'' AND C.ProductID = P.ProductID ORDER BY NEWID()" |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2005-04-27 : 09:30:20
|
| If you look at the master set of data from the query....ie excluding the "TOP 2" bit....do you get duplicate rows and are they meant to be there? If the answer to the latter question is "no"...then resolving that will solve your original problem.If "yes"...then the following might work?SELECT TOP 2 P.*, DISTINCT(C.CatID) FROM JEP_tblProducts P, JEP_LtblProductCategories C WHERE P.Image1<>'' AND C.ProductID = P.ProductID ORDER BY NEWID()" |
 |
|
|
|
|
|