1

Why information_schema.columns always duplicates the result? For instance,

SELECT column_name 
FROM information_schema.columns 
WHERE table_name = 'root_blocks'

I will get this,

column_name

blc_id
blc_email
cat_id
blc_created
blc_updated
blc_id
blc_email
cat_id
blc_created
blc_updated

The duplicates go unpredictable on other tables when I try to query through phpmyadmin.

How can I make it not to duplicate?

Thanks.

EDIT:

enter image description here

4

2 回答 2

4
SELECT column_name 
FROM information_schema.columns 
WHERE table_name = 'root_blocks'
AND `table_schema` = 'SCHEMA_NAME'

请试试这个。

如果您想从所有数据库中选择并获取唯一的列名,那么请试试这个..

SELECT DISTINCT(column_name) 
    FROM information_schema.columns 
    WHERE table_name = 'root_blocks'
于 2011-03-25T15:32:27.537 回答
2

也许您在多个模式中有同一个表?

如果你运行会发生什么:

SELECT table_schema, column_name 
FROM information_schema.columns 
WHERE table_name = 'root_blocks'
于 2011-03-25T15:42:52.273 回答