mysql query for sample from table

I need a mysql query to extract a sample of n rows from a table with r records.
robrodpAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
Here's the basic version.

$nrows = 22;  // example value for rows
$sql = "SELECT * FROM yourtable LIMIT $nrows";

Open in new window


This page http://dev.mysql.com/doc/refman/5.1/en/select.html shows all the variations for a SELECT statement.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The SQL Server 2012 answer would be TABLESAMPLE.  Don't know if this works in MySQL.
http://msdn.microsoft.com/en-us/library/ms189108(v=sql.105).aspx

use adventureworks2012
go

SELECT *
FROM Person.Address
TABLESAMPLE (500 ROWS) 
GO

Open in new window

0
 
robrodpAuthor Commented:
I need it for MySql
0
 
robrodpAuthor Commented:
Bit that wont get me a random sample right?
0
 
robrodpAuthor Commented:
I got it. Sorry I did not state the random part inmy question.

SELECT * FROM table ORDER BY RAND() LIMIT 10000
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.