In MySQL, the syntax DESCRIBE
can show a table's structure, but it cannot be embedded to normal statement; is there some tricky way to do it?
For example, this shows the table1
structure, returned as a table (but SQL statement does not think so)
DESCRIBE `table1`
But this doesn't work:
SELECT * FROM (DESCRIBE `table1`)
Is there a way to enable it?
I want to join the "table" created by DESCRIBE
syntax, how can I do it?
You can use COLUMNS table of INFORMATION_SCHEMA to get expected result as an alternate solution of DESCRIBE table option.
Try this:
SELECT COLUMN_NAME AS `Field`, COLUMN_TYPE AS `Type`, IS_NULLABLE AS `NULL`,
COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS `Extra`
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'schemaName' AND TABLE_NAME = 'table1';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With