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
 SQL Server Development (2000)
 How to get batch random record from table?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-01 : 09:02:58
jane writes "There are 2 tables: A and B
A has 2 fields: user_id, name
B has 1 field: name ( the name included name of Table A)
Now, I need choose 5 random name from table B for each user_id of table A, and these 5 name should exclude the name of corresponse user_id of table A.

select A.user_id,B.name
from A , (select top 5 name from B order by newid()) B
where B.name not in (select name from A where user_id=A.user_id)

but I get the same name for each user_id, I hope they should different result, How can I get this in sql statement?

thanks"

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2002-03-01 : 09:02:58
Check out these articles: http://www.sqlteam.com/FilterTopics.asp?TopicID=135
Go to Top of Page
   

- Advertisement -