How can I select all columns except the primary key from a table? It should be noted that I don't know field names in this table, the operation should be able to run automatically.
Thank you for the help.
How can I select all columns except the primary key from a table? It should be noted that I don't know field names in this table, the operation should be able to run automatically.
Thank you for the help.
Use:
To get All columns Without primary use
SELECT `COLUMN_NAME` FROM `information_schema`.`COLUMNS` WHERE (`TABLE_SCHEMA` = 'wpresstest') AND (`TABLE_NAME` = 'wp_countries') AND (`COLUMN_KEY` <> 'PRI')
See you cant do all using simple SQL.So
Either use mysql Prepare Execute statement Or use PHP way like:
1)This would be your 1st Query as above.You will get All column names Excluding primary.OK?
2)Now fetch the resulted array in PHP
.and build dynamic query for Comma separated Column names you just got.
3)Now fire 2nd query to fetch ROWS .Here you will include SELECT (Column1,Column2) from TBL
.
And after getting column names , you can fire query to return Result based on Returned columns