Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Primary Key Value Without Knowing Field Name

I have 3 tables, images, icons, and banners, each with a unique primary key that is also auto_incremented named image_id, icon_id, and banner_id, respectively.

I'm looping through the above tables and I'm wondering if there's a way I can select the id column without specifying it's specific name.

Something like

SELECT PRIMARY_KEY
FROM {$table}

Where I don't have to change my table structure or use * as there would be much data to return and would slow down my application.

like image 290
Steve Robbins Avatar asked Sep 16 '25 21:09

Steve Robbins


1 Answers

Just name the id columns id in each table. Reserve the whatever_id naming for foreign keys.

like image 79
Marc B Avatar answered Sep 18 '25 13:09

Marc B