2013-03-07 10 views
0

我正在嘗試使用:如何獲取包含條件的列名?

從#__表名顯示列WHERE Field.columnname ='any value';

如果我在沒有條件的情況下使用它,那麼它將檢索所有列名稱,但我想獲取指定的列名稱。

請建議。

+0

你應該使用Where條件,你不能沒有獲取任何地方特定列。你爲什麼不想用'where'? – 2013-03-07 06:43:17

+0

當我使用上述查詢不起作用的地方.. – 2013-03-07 06:46:49

回答

1

您可以使用information_schema.columns表而不是SHOW COLUMNS語句。 information_schema.columns表與SHOW COLUMNS相同,但您可以像普通表一樣使用結果集。例如 -

SELECT * FROM information_schema.columns 
WHERE table_schema = 'table name' AND table_name = 'table name'; 

指定您需要的列和WHERE過濾器。

+0

但它會獲取所有cloumns,但我只想獲取符合指定條件的列。 – 2013-03-07 06:51:13

+0

你想通過面具獲取字段名稱嗎? – Devart 2013-03-07 06:54:22

0

可以使用information_schema.columns,並添加過濾器來獲取你想要的列,我覺得它的工作原理

SELECT * FROM information_schema.columns 
    WHERE table_schema = 'table name' 
      AND table_name = 'table name' 
      AND column_name = 'Column name' 
相關問題