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 8125227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:44:50+00:00 2026-06-06T06:44:50+00:00

I have 2 tables that I am working with that use the same column;

  • 0

I have 2 tables that I am working with that use the same column; one table contains the text and the other table contains the images; they use the column listing_id so that the right text shows up with the right images;

my problem is that because column listing_id is auto-increment, my first table is able to have an insert into query that is able to insert the text and then +1 the column listing_id; however the 2nd table I use another INSERT INTO query will not have the right listing_id,

because some entries for listing_id have been deleted, meaning that the 2nd table’s listing_id will always be behind the 1st tables listing_id;

how do I reference the column listing_id?

  • 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-06-06T06:44:52+00:00Added an answer on June 6, 2026 at 6:44 am

    You need to create an INT column called something like “parent_id” in the dependant tables that stores the id of the main table that it is referencing. When you select records from the first, you would then JOIN the tables with the auto_increment field of the first field against the “parent_id” of the second.

    As MrSlayer mentions, use the newly inserted ID of the first table to update “parent_id”. You should typically have a unique ID field in the second table for uniqueness, but it shouldn’t be part of the relationship to the first table.

    If you’re unclear about how to get the id that the first table auto_increments to when you insert, use mysql_insert_id().

    mysql_query("INSERT INTO table1 ...");
    echo "Last inserted record_id in table1 was " .  mysql_insert_id();
    
    INSERT INTO table1 (mytextcolumn) VALUES('text');
    INSERT INTO table2 (parent_id,image_name) VALUES(LAST_INSERT_ID(),'someimage.png'); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many tables that use Lookup/Enum references for most of their column values.
I'm working on a project that will have a single table holding lots and
I have some tables that benefit from many-to-many tables. For example the team table.
I have two tables that are related via a mapping table: keywords titles I
I have 2 tables that their rows have one on one relation.. For you
I have a table with a column that I want to extract out and
I have two tables that should be joined together by a foreign key relationship,
I have two tables that are considered a single entity in my domain model.
I have two tables that I am joining with the following query... select *
I have several tables that I want to put side by side, however when

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.