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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:27:04+00:00 2026-06-13T12:27:04+00:00

I have 2 tables as below, and insert data into ftable from f_table accordingly.

  • 0

I have 2 tables as below, and insert data into ftable from f_table accordingly. I want to insert field_3 into field3 if field_3 exists, else insert field_4 into field3.

How do I do that? Much appreciate for any reply.

CREATE TABLE ftable
(
field1 int null,
field2 int null,
field3 char(1)
);

CREATE TABLE f_table
(
field_1 int null,
field_2 int null,
field_3 char(1),
field_4 char(1)
);

INSERT INTO ftable (field1, field2, field3) 
    SELECT (field_1, field_2, field_3) 
    FROM f_table;
  • 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-13T12:27:05+00:00Added an answer on June 13, 2026 at 12:27 pm

    Not sure what you really mean by if field_3 exists – since it’s part of the table, that column always exists…

    Guessing that you probably mean: if it’s NOT NULL – in that case, use this CASE statement:

    INSERT INTO ftable (field1, field2, field3) 
        SELECT 
           field_1, field_2, 
           CASE
               WHEN field_3 IS NOT NULL THEN field_3
               ELSE field_4
           END
        FROM f_table;
    

    Update: as per w0lf’s suggestion, you could also use:

    INSERT INTO ftable (field1, field2, field3) 
        SELECT 
           field_1, field_2, 
           ISNULL(field_3, field_4)
        FROM f_table;
    

    Makes it a bit more compact – but a tad less readable, in my opinion. But this will work just fine – if field_3 is NULL, then field_4 is inserted instead.

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

Sidebar

Related Questions

I have a mysqli/php code below where it is suppose to insert data into
I have created the SQL script below that creates four tables and inserts data
I have two MySql tables as shown below with the data shown: CREATE TABLE
I am new to entityframework, and was trying to insert data into relational tables.
I have a script that i use to load my data into my tables
I have a signup page and basically I need data inserted into 4 tables.
Possible Duplicate: Unable to insert data into multiple wordpress tables According to the above
I have two tables & data as below. create table t1 (id int, name
I have two tables described below. What I need is a single query that
i have four tables like below in sql server 2008 : TABLE 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.