- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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)
- How do I truncate tables properly in MySQL?
- How do I create a random four-digit number in MySQL?
- MySQL SELECT from two tables with a single query
- How to select a random record from a MySQL database?
- How to join tables and fetch values from a MySQL database?
- How Can I check the size of the tables in a particular MySQL database?
- Get all the tables from a MySQL database having a specific column, let’s say xyz?
- How can I check MySQL tables from a database in accordance with particular column/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 can I merge two MySQL tables?
- Find the greatest value among four tables in MySQL?
- How to get the size of the tables of a MySQL database?
- MySQL count(*) from multiple tables?
- Can I use InnoDB and MyISAM tables in a single database in MySQL?