Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7571515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:41:34+00:00 2026-05-30T15:41:34+00:00

I have 3 tables, images , icons , and banners , each with a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:41:36+00:00Added an answer on May 30, 2026 at 3:41 pm

    I’m not a LAMP guy, but it looks to me like you want the INFORMATION_SCHEMA tables.

    A query something like :

    SELECT     pk.table_name, column_name as 'primary_key'
    FROM       information_schema.table_constraints pk 
    INNER JOIN information_schema.key_column_usage C 
                                        on c.table_name = pk.table_name  and
                                           c.constraint_name = pk.constraint_name
    where   constraint_type = 'primary key'
               -- and pk.table_name  LIKE '%whatever%'
    

    This above query (filtered to whatever relevant set of tables you need) will give you bit a list of table names and associated Primary Keys. What that information on hand you could query something like :

    SELECT {$PK_ColumnName}
    FROM {$table}
    

    Note, you might needs a more complicated syntax and string builder if you have composite primary keys (i.e. more than one field per key). Also, the information schema can be relatively expensive to query, so you’ll either want to cache the result set up, or query it infrequently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have a database with two tables, that is, Updates table and Images
I have two tables, images and image_data and here is an example of my
I have two tables, content and images (and a ContentImages table for the one
I basically have three tables, posts, images and postimages (this simply contains the ids
If we have two tables, say; users, and images, how do we select users
I have stored page contents (tables, plain text, images and paragraphs) into a variable.
I have an index.html.erb page timesheet that has various js and jquery tables and
I have a table view that displays a list of users. The avatar images
I have a menu like this: <div id=header> <div id=nav> <ul> <li><a href=/home/><img src=/images/icons/home.png
I have two tables images2 and image_data So the goal is to have 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.