Is there a way to describe the columns of a joined table in SQL?
If I have just one table, for example A I can do
DESC A
But how can I show the columns of a joined table? Something like
DESC A INNER JOIN B on A.id_a = B.id_b
DESCRIBE
is a synonym for SHOW COLUMNS
. That only works for tables and views.
To get that to work for a "join" of two tables, if we have sufficient privileges, we could create view object, e.g
CREATE VIEW _temp_ AS SELECT a.*, b.* FROM a JOIN b ON a.id_a = b.id_b
and then we could do a SHOW COLUMNS
from the view:
SHOW COLUMNS FROM _temp_ ;
We can get the same result using one of the aliases for SHOW COLUMNS
...
DESCRIBE _temp_ ;
or
EXPLAIN _temp_ ;
Then we should drop the view:
DROP VIEW _temp_ ;
(It's not entirely clear what problem we are attempting to solve; I only addressed the question that was asked, how to get DESC
to work for an inner join.)