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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:33:36+00:00 2026-06-13T13:33:36+00:00

I have a tbl, for example: uniqueId | col1 | col2 | col3 u1

  • 0

I have a tbl, for example:

uniqueId     |    col1    |    col2   |   col3   
u1                 8       
u2
u3                 13           89

What I want is to insert into the first empty column (can make them null if that helps). In the given if I’ll add to u1 the value 2 it will be inserted into col2. If I do it for u2, it will enter col1. and for u3 it will enter to u3. These three queries will do the trick but I would rather do it in one.

INSERT INTO tbl SET col1 = $toInsertVal WHERE uniqueId=u col1=''
INSERT INTO tbl SET col2 = $toInsertVal WHERE uniqueId=u col1<>'' AND col2=''
INSERT INTO tbl SET col3 = $toInsertVal WHERE uniqueId=u col1<>'' AND col2<>'' AND col3=''

  • 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-13T13:33:37+00:00Added an answer on June 13, 2026 at 1:33 pm
    insert into tbl set 
    col1 = case when col1 = '' then $toInsertVal else col1 end
    , col2 = case when col2 = '' and col1 <> '' then $toInsertVal else col2 end
    ...
    where uniqueid = u
    

    I’ve ignored NULLs for the sake of simplicity. Basically you can use a CASE on each column, checking on the first empty column and setting its value to its current value if no change is required.

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

Sidebar

Related Questions

For example, I have a table tbl like values 10 20 30 40 on
i have one table, let's call it 'TBL'. i have one column that have
I have the following data on a table tbl Admission : Date and Time
I have the following tables: 1) TBL (ID, Data, LastUpdated, DateCreated) 2) TBL_LOG(Log_ID, LogCreateDate,
I have a table tbl_Info : InfoId Text PrivacyTypeId UserName TypeId IsInfo InfoItemId Example
I have a tricky situation in trying to get information from multiple queries into
I have these data from a table. Example, I have table for points named
I have 5 variables which can either be true or false and I have
I have two tables, one containing a list of different options users can select
I have a full-text index created upon a column of type varchar(max) with filestream

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.