How can I return column names in dot notation in MySQL? I want to return column names into a table. But I also want to avoid redundancies like 'id' and 'id'. 

I did:

INSERT INTO columns(name) 
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 
WHERE table_name='contacts' or table_name='companies';


But as expected I get id from the first table showing up with the same field name. 

How do I get it in the form: contacts.id and companies.id?
You first try was very close. Just prepend the table_name and a dot:

INSERT INTO columns(name) 
SELECT CONCAT(TABLE_NAME,'.',COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS 
WHERE table_name='contacts' or table_name='companies';


Give it a Try !!!