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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:23:32+00:00 2026-06-07T11:23:32+00:00

I have two tables: images and servers . Here’s the schema relating to those

  • 0

I have two tables: images and servers. Here’s the schema relating to those two tables:

id, name, uploaded, views, server_id

id, name, description, drive_space, enabled

On the images table, server_id is a foreign key to the id field in the servers table. Pretty simple stuff. Many images belong to one server.

When I insert an image, it has to have a key pointing to the server the image is hosted on. When I insert the row, I’m given the name of the server (not its id) so I can’t just insert it. I can achieve what I want with two queries (one to get the server ID and another to insert the image into the database) but idealy I want it done in one query with a JOIN as it’s best practice.

I’m almost clueless with JOINS when it comes to SELECT statements and even more so with an INSERT. Can anyone help me out?

  • 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-07T11:23:33+00:00Added an answer on June 7, 2026 at 11:23 am

    No need for a join. Just use a INSERT … SELECT …:

    INSERT INTO images
    (name, uploaded, views, server_id)
    SELECT 'imagename', CURTIME(), 0, id
    FROM servers
    WHERE name = 'servername'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, images and image_data and here is an example of my
I have two seperate tables in my DB, here the relevant fields: table images:
I have two tables, content and images (and a ContentImages table for the one
If we have two tables, say; users, and images, how do we select users
Basically I have a database with two tables, that is, Updates table and Images
I have two tables. One with information about properties. The other stores 3 images
I have two tables: listings(item_id, ...) images(item_id, ...) The item_id value is the same
I have two tables: one that stores blogs and the other that stores images
Consider I have two database tables: images and albums . They have these schemas:
I have two tables: Actor and Images. The Images table is linked to the

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.