2

I am trying to write a query which lists the names of the columns in an SQL table, however, I don't want all the columns - just specific ones. So, for example, if I was to put the COMMENT = 'test' for the columns which I want to list then I thought my query would be:

SHOW COLUMNS FROM `tbl_name` WHERE `COMMENT`='test'

This however throws an error.

Any ideas?

Thanks,

1
  • I don't think its possible. SHOW is not a SELECT. So no WHERE clause. Commented Oct 20, 2014 at 10:53

2 Answers 2

4

I think you can do this using information_schema.columns:

select column_name
from information_schema.columns c
where table_name = 'tbl_name' and
      column_comment = 'test';
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this worked perfectly. I just looked up the information.schema and it means I can essentially categorise my columns now for different users. Thanks!
0

I think that SHOW COLUMNS can't have the WHERE clause, but you can try this:

SHOW COLUMNS FROM (SELECT * FROM `tbl_name` WHERE `COMMENT`='test')

Comments

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.