-2

Is there any way to get last entry from all tables? I even did not find way to query all tables, tried this:

SELECT * FROM *
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
21ewq
  • 9
  • 1
  • 1
    Possible duplicate, show all tables in sql https://stackoverflow.com/questions/175415/how-do-i-get-list-of-all-tables-in-a-database-using-tsql – davidev Nov 22 '19 at 19:25
  • Tables have to be named explicitly in queries, you can't use variables or patterns. You'll need to write dynamic SQL that gets the table names from `INFORMATION_SCHEMA` – Barmar Nov 22 '19 at 19:36

1 Answers1

0

Yeah, you can do whatever you want in SQL, this query will give you 10 last data from your table, there we go:

Example:

SELECT * FROM tablename ORDER BY id DESC LIMIT 10;

put table name and id number which is primary key. you can also put any number in LIMIT 5 like this!

SELECT TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME RLIKE '_posts' ORDER BY TABLE_NAME DESC LIMIT 10`

think about the data which you want to fetch, so place the row's name after ORDER BY. it's done!

don't forget to study in W3school.

Thanks!

Ericgit
  • 6,089
  • 2
  • 42
  • 53
  • 2
    You probably understood me wrong. This query displays all tables: `SELECT 'TABLE_NAME' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME RLIKE '_posts'` How to use this as dynamic table list? – 21ewq Nov 23 '19 at 09:28
  • 2
    Does same thing as code in first comment, I tried to use it as FROM table list. Thanks for trying though. – 21ewq Nov 23 '19 at 09:57