2

TO show indexes we use the following query,

show indexes from student;
+---------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table   | Non_unique | Key_name              | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| student |          0 | PRIMARY               |            1 | ROLL_NO     | A         |           6 |     NULL | NULL   |      | BTREE      |         |               |
| student |          1 | stu_roll_no_age_index |            1 | ROLL_NO     | A         |           6 |     NULL | NULL   |      | BTREE      |         |               |
| student |          1 | stu_roll_no_age_index |            2 | AGE         | A         |           6 |     NULL | NULL   | YES  | BTREE      |         |               |
+---------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+--------------+

Now I am trying to select only Table from the above as follows,

select Table, Key_name, Column_name,Index_type from (show indexes from student);

I think I might be wrong but I am not getting how to reason it? Please tell me. And also , how do I get only specific columns from the result of such query.

1
  • 1
    You can not do this. Try Sysindexes rather. Commented Sep 12, 2018 at 13:12

1 Answer 1

1

You can use table STATISTICS from db information_schema, like this:

select TABLE_NAME, INDEX_NAME, COLUMN_NAME, INDEX_TYPE
from information_schema.STATISTICS WHERE TABLE_NAME = 'student';
Sign up to request clarification or add additional context in comments.

2 Comments

Nice one.. It worked. :).. Can you please tell me what is wrong with my approach?
Your approach wasn't wrong, it's just impossible to select something from show index query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.