How to limit SHOW TABLES query

元气小坏坏 提交于 2019-11-29 12:38:34

问题


I have the following query:

SHOW TABLES LIKE '$prefix%'

It works exactly how I want it to, though I need pagination of the results. I tried:

SHOW TABLES LIKE '$prefix%' ORDER BY Comment ASC LIMIT 0, 6

I need it to return all the tables with a certain prefix and order them by their comment. I want to have pagination via the LIMIT with 6 results per page.

I'm clearly doing something very wrong. How can this be accomplished?

EDIT: I did look at this. It didn't work for me.


回答1:


The above cannot be done via MySQL Syntax directly. MySQL does not support the LIMIT clause on certain SHOW statements. This is one of them. MySQL Reference Doc.

The below will work if your MySQL user has access to the INFORMATION_SCHEMA database.

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'DATABASE_TO SEARCH_HERE' AND TABLE_NAME LIKE "table_here%"  LIMIT 0,5;



回答2:


Just select via a standard query instead of using SHOW TABLES. For example

select table_name from information_schema.tables

Then you can use things like ASC and LIMIT, etc...



来源:https://stackoverflow.com/questions/11635769/how-to-limit-show-tables-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!