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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:08:14+00:00 2026-05-28T08:08:14+00:00

I am insertnig into a table using a selection INSERT california_authors (au_id, au_lname, au_fname)

  • 0

I am insertnig into a table using a selection

INSERT california_authors (au_id, au_lname, au_fname)
SELECT au_id, au_lname, au_fname
FROM authors
WHERE State = 'CA'

say i have an identity column in california_authors. Can i get all the ids inserted by the above particular insertion just like i can get @@IDENTITY for last single insertion ?

I can’t use select command for california_authors as there may exists previously inserted records with filter State = 'CA'

  • 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-28T08:08:15+00:00Added an answer on May 28, 2026 at 8:08 am

    You can use the output clause.

    Something like this if your identity column is named `IdentityCol’ will return you id’s as a result set.

    INSERT california_authors (au_id, au_lname, au_fname)
    OUTPUT inserted.IdentityCol
    SELECT au_id, au_lname, au_fname
    FROM authors
    WHERE State = 'CA'
    

    You can insert the id’s to a table using output ... into.
    Here is a sample that stores the id’s in a table variable.

    declare @IDs table (id int)
    
    INSERT california_authors (au_id, au_lname, au_fname)
    OUTPUT inserted.IdentityCol INTO @IDs
    SELECT au_id, au_lname, au_fname
    FROM authors
    WHERE State = 'CA'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm inserting records from one table into another table using a select statement. The
I'm try to insert values into my sqlite table using a python script. It
Here is the code I am using to insert a record into the table...
I'm inserting multiple records into a table A from another table B. Is there
I am inserting into a table by using the newxt query, but I dont
Me again! I have a question re. inserting into a sql table using LINQ.
I am using NHibernate 2.1. I am inserting records into a table successfully, but
I'm currently using the CURRENT_DATE when inserting into my table field for the Date.
I am importing approx 350,000 lines from a CSV file into MySQL using PHP
There are existing options for doing bulk insert into a single table with EF

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.