Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to get the column names from a mysql database, with a query.
Can someone please help?
Thanks.

What I have tried:

SELECT column_name FROM information_schema.columns WHERE table_schema = 'YOUR_DATABASE_NAME' AND table_name = 'YOUR_TABLE_NAME'

SHOW COLUMNS FROM mydb.mytable;
Posted
Updated 22-Dec-17 8:03am
Comments
Richard MacCutchan 20-Dec-17 15:50pm    
Help how?

SQL
show full tables where Table_Type = 'BASE TABLE'

or just
SQL
show tables



SORRY - I've answered the wrong question - again!

to see the colums se:

SQL
SHOW COLUMNS FROM [table_name]
 
Share this answer
 
v4
Comments
Richard MacCutchan 21-Dec-17 5:30am    
Glad I'm not the only one. :)
SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('columnA','ColumnB') AND TABLE_SCHEMA='YourDatabase';
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900