MySQL sort DESC

Hello,

How can I sort largest to smallest?
Like “ORDER BY Data_length DESC”

[php]
$result = $mysqlibag->query(“SHOW TABLE STATUS”);
while($table = $result->fetch_array()) {
echo “Table Name: “.$table[‘Name’].” Rows: “.$table[‘Rows’].” Size: “.$table[‘Data_length’].”
”;
}
[/php]

Thanks

SHOW TABLE is just some built in stuff which really isn’t usable for much. I think this query would do the trick

SELECT TABLE_SCHEMA, TABLE_NAME, (INDEX_LENGTH+DATA_LENGTH)/(1024*1024) AS SIZE_MB, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'your_db_name' ORDER BY SIZE_MB DESC LIMIT 10;

Thank you very much, it worked excellent.

But, I use include(“config.php”); , Do I need to this? ‘your_db_name’

Try it without, but you should be able to use the database name defined in the config file

This is working, WHERE TABLE_SCHEMA = ‘$db_name’

Again thank you very much

Sponsor our Newsletter | Privacy Policy | Terms of Service