Re: random start to query
Scott --Original Message- I have a database table with say 100 rows. What I would like is to preform a query starting at a random place within the table, that will wrap around if I want it to. That is if the query starts returning results at the 98th row, then I would want it to return 98, 99, 100, 1, 2, . I know that mysql has the RAND() function but how can I determine on the fly how many rows are in my table, and what would the SQL statement look like? And how can I get the query to wrap? I'm a relative newcomer to this stuff myself, but you may have to do two separate queries for this - one to determine the row count, then another two-parter, using your random number in the first SQL (LIMIT) statement, with a UNION SQL statement to a similar query for the rest. Does that help? Terry -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: random start to query
Scott --Original Message- What would be the most efficient query to determine the number of rows? Probably something like SELECT COUNT(*) AS rectotal FROM table ? Cheers Terry PS - better to reply direct to list rather than individual, as you seem to have done on this occasion :-} -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 10:50 AM To: [EMAIL PROTECTED] Subject: Re: random start to query Scott --Original Message- I have a database table with say 100 rows. What I would like is to preform a query starting at a random place within the table, that will wrap around if I want it to. That is if the query starts returning results at the 98th row, then I would want it to return 98, 99, 100, 1, 2, . I know that mysql has the RAND() function but how can I determine on the fly how many rows are in my table, and what would the SQL statement look like? And how can I get the query to wrap? I'm a relative newcomer to this stuff myself, but you may have to do two separate queries for this - one to determine the row count, then another two-parter, using your random number in the first SQL (LIMIT) statement, with a UNION SQL statement to a similar query for the rest. Does that help? Terry -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: random start to query
I think I found another answer to my own question. FYI a good way to return results in a random order SELECT user FROM table ORDER BY RAND() -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 11:08 AM To: [EMAIL PROTECTED] Subject: RE: random start to query Scott --Original Message- What would be the most efficient query to determine the number of rows? Probably something like SELECT COUNT(*) AS rectotal FROM table ? Cheers Terry PS - better to reply direct to list rather than individual, as you seem to have done on this occasion :-} -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 10:50 AM To: [EMAIL PROTECTED] Subject: Re: random start to query Scott --Original Message- I have a database table with say 100 rows. What I would like is to preform a query starting at a random place within the table, that will wrap around if I want it to. That is if the query starts returning results at the 98th row, then I would want it to return 98, 99, 100, 1, 2, . I know that mysql has the RAND() function but how can I determine on the fly how many rows are in my table, and what would the SQL statement look like? And how can I get the query to wrap? I'm a relative newcomer to this stuff myself, but you may have to do two separate queries for this - one to determine the row count, then another two-parter, using your random number in the first SQL (LIMIT) statement, with a UNION SQL statement to a similar query for the rest. Does that help? Terry -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: random start to query
Great!Didn't know you could do that. Cheers Terry --Original Message- I think I found another answer to my own question. FYI a good way to return results in a random order SELECT user FROM table ORDER BY RAND() -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: random start to query
I think I found another answer to my own question. FYI a good way to return results in a random order SELECT user FROM table ORDER BY RAND() Unfortunately, you cannot use this query to wrap around, as you put it. Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: Carter, Scott [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, 29 May, 2003 12:35 Subject: RE: random start to query I think I found another answer to my own question. FYI a good way to return results in a random order SELECT user FROM table ORDER BY RAND() -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 11:08 AM To: [EMAIL PROTECTED] Subject: RE: random start to query Scott --Original Message- What would be the most efficient query to determine the number of rows? Probably something like SELECT COUNT(*) AS rectotal FROM table ? Cheers Terry PS - better to reply direct to list rather than individual, as you seem to have done on this occasion :-} -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 10:50 AM To: [EMAIL PROTECTED] Subject: Re: random start to query Scott --Original Message- I have a database table with say 100 rows. What I would like is to preform a query starting at a random place within the table, that will wrap around if I want it to. That is if the query starts returning results at the 98th row, then I would want it to return 98, 99, 100, 1, 2, . I know that mysql has the RAND() function but how can I determine on the fly how many rows are in my table, and what would the SQL statement look like? And how can I get the query to wrap? I'm a relative newcomer to this stuff myself, but you may have to do two separate queries for this - one to determine the row count, then another two-parter, using your random number in the first SQL (LIMIT) statement, with a UNION SQL statement to a similar query for the rest. Does that help? Terry -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]