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

  • Home
  • SEARCH
  • 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 4541918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:18:47+00:00 2026-05-21T15:18:47+00:00

So to clear up the question a bit, I have a table we’ll call

  • 0

So to clear up the question a bit, I have a table we’ll call it “tAuthor” and another table called “tBook”. The tables have the following columns.

tAuthor

  • id – INT (PK)
  • fname – VARCHAR(50)
  • lname – VARCHAR(50)

tBook

  • id – INT (PK)
  • authorid – INT (PK)
  • name – VARCHAR(50)

If I had the authors firstname and lastname and wanted to insert a new book into tBook for them, is there an easy way to have the insert statement auto fill in the authorid WHERE fname = “Known” and lname = “Known”?

I figured I could always have two statements, a select statement that returns the id WHERE fname=”Known” and lname=”Known” and then run the insert statement with the id returned. I was just curious if there was another way?

  • 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-21T15:18:48+00:00Added an answer on May 21, 2026 at 3:18 pm
    INSERT INTO tBook (name, authorid)
    VALUES(SELECT 'NewBook', id
           FROM tAuthor
           WHERE tAuthor.fname = 'FirstName'
           and tAuthor.lname = 'LastName')
    

    I wouldn’t recommend using an Authors name for this as there could be duplicates. However this statement will do the insert you require. You basically do a sub-select from the table you need your ID from and fill in the rest of the information as hardcoded values rather than values to retrieve. This is also a great way to do multiple updates if you need to update a bigger set of records that all share a common element.

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

Sidebar

Related Questions

The question is clear from the title. Is there an SDK for the Java
Excuse me, I do not make a clear question in english. I need some
Consider the following snap on my site. The area in red is a table
Simple question - I've got a bucketload of cruddy html pages to clean up
I'm not clear on the differences between the current version of Ruby (1.8) and
I want to clear the list of projects on the start page...how do I
Is there a way clear or reset the outputcache for an entire website without
Is there any clear documentation on the binary formats used to serialize the various
Now that it's clear what a metaclass is , there is an associated concept
How do you clear the IRB console screen?

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.