0

This is in Microsoft SQL Server CE, I have the following table

TABLE

[ID]  [eventID]  [factString]

I am trying to randomly select the factString off of one row from the above table where the eventID equals a specific number.

 (randomly) 
 SELECT factString 
 FROM factTable 
 WHERE eventID = 1

That is to say, if there are 10 rows where the eventID is 1, I want to return one row which is random every time.

Thanks.

4

2 回答 2

0

您可以添加 ORDER BY Rand()

 SELECT factString 
 FROM factTable 
 WHERE eventID = 1 
 ORDER BY Rand()

并且 LIMIT 1 仅适用于 1 行

于 2012-12-02T08:50:54.350 回答
0

如果你只想要 1 行,你应该添加top 1SQL。

SELECT TOP 1 factString 
FROM factTable 
WHERE eventID = 1 
ORDER BY Rand()
于 2012-12-02T08:56:38.113 回答