- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I select four random tables from a MySQL database having thousands of tables?
To select four random tables, use ORDER BY RAND(). Following is the syntax −
select TABLE_NAME AS anyAliasName from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = ‘yourDatabaseName’; order by rand() limit yourLimitNumber;
Let us implement the above syntax in order to select four random tables from a MySQL database that has thousands of tables.
Here, LIMIT is used to set the number of records you want to fetch. Since we want 4 records, therefore we would be using LIMIT 4. Following is the query −
mysql> select TABLE_NAME AS Random4TableName from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'web' order by rand() limit 4;
This will produce the following output −
+------------------+ | Random4TableName | +------------------+ | demotable474 | | demotable313 | | demotable452 | | demotable382 | +------------------+ 4 rows in set (0.20 sec)
- Related Articles
- How do I truncate tables properly in MySQL?
- Get all the tables from a MySQL database having a specific column, let’s say xyz?
- How to join tables and fetch values from a MySQL database?
- MySQL SELECT from two tables with a single query
- How to select a random record from a MySQL database?
- How Can I check the size of the tables in a particular MySQL database?
- How can I check MySQL tables from a database in accordance with particular\ncolumn/s name?
- While connecting to one MySQL database, how can I see the list of tables of other MySQL database?
- How to count the number of tables in a MySQL database?
- How to get the size of the tables of a MySQL database?
- How do I create a random four-digit number in MySQL?
- How can we analyze the tables of a particular database from MySQL Server command line?
- Can I use InnoDB and MyISAM tables in a single database in MySQL?
- How can I merge two MySQL tables?
- How can I describe all tables in the database through a single statement in MySQL?