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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:06:54+00:00 2026-05-20T15:06:54+00:00

I want to know if it is possible to create another column in a

  • 0

I want to know if it is possible to create another column in a table that has data that I wish to populate in this new column? The new column is Flag2. Here is the table:

enter image description here

what I want to do is, where item id is 30, I want the ITEM ID to only display 30 once and, populate the QC Unsupportted in Flag2? How do I do this?

I can only think of doing an inner join but this is not working.

This is what I have done in trying to do so:

SELECT 
    A.ITEMID, A.FLAG1, A.FLAG2 
FROM 
    #FLAGS as A
INNER JOIN 
    #FLAGS as B ON A.ITEMID = B.ITEMID
GROUP BY 
    a.ITEMID, a.FLAG1, A.FLAG2
ORDER BY 
    ITEMID
  • 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-20T15:06:55+00:00Added an answer on May 20, 2026 at 3:06 pm

    Assuming I understand what you are after, if the current FLAG1 values are distinct for any ITEMID and you only have at most two instances of the same ID, I think this should do what you want:

    SELECT
        lft.ITEMID
      , lft.FLAG1
      , rght.FLAG1 FLAG2
    FROM (
      SELECT
          t.ITEMID
        , t.FLAG1
      FROM (
        SELECT
            l.ITEMID
          , l.FLAG1
          , COUNT(l.ITEMID) i
        FROM #FLAGS l
          INNER JOIN #FLAGS r ON l.ITEMID = r.ITEMID
        WHERE r.FLAG1 <= l.FLAG1
        GROUP BY
            l.ITEMID
          , l.FLAG1) t
      WHERE t.i=1) lft
      LEFT OUTER JOIN (
      SELECT
          t.ITEMID
        , t.FLAG1
      FROM (
        SELECT
            l.ITEMID
          , l.FLAG1
          , COUNT(l.ITEMID) i
        FROM #FLAGS l
          INNER JOIN #FLAGS r ON l.ITEMID = r.ITEMID
        WHERE r.FLAG1 <= l.FLAG1
        GROUP BY
            l.ITEMID
          , l.FLAG1) t
    WHERE t.i=2) rght ON lft.ITEMID = rght.ITEMID
    
    -- Or better
    SELECT
        lft.ITEMID
      , lft.FLAG1
      , rght.FLAG1 FLAG2
    FROM (
      SELECT
          t.ITEMID
        , t.FLAG1
      FROM (
        SELECT
            l.ITEMID
          , l.FLAG1
          , ROW_NUMBER() OVER(PARTITION BY ITEMID ORDER BY FLAG1) as i
        FROM test l) t
      WHERE t.i=1) lft
      LEFT OUTER JOIN (
      SELECT
          t.ITEMID
        , t.FLAG1
      FROM (
        SELECT
            l.ITEMID
          , l.FLAG1
          , ROW_NUMBER() OVER(PARTITION BY ITEMID ORDER BY FLAG1) as i
        FROM test l) t
      WHERE t.i=2) rght ON lft.ITEMID = rght.ITEMID
    

    If you have additional flag values for the same ID, a new outer join can be added to a new inline table (rght2, rght3, etc.) where i=3, 4, etc. and you are selecting rght2 AS FLAG3, rght3 AS FLAG4, etc.

    Also note that the current values for FLAG1 will be distributed through FLAG1 and FLAG2 in alphabetical order. If you wanted to distribute them in reverse order you could replace <= with >=. If you had more than two flags that you wanted distributed in a specific order, you would have to create a separate table with a ranking value and join to that which would be doable but even uglier!

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

Sidebar

Related Questions

I want to know if it is possible to stream data from the server
Hey i dont know if that is possible but i want to set a
Is it possible to create a table which has a check constraint on one
I just want to know if it is possible to create a hashtable in
Possible Duplicate: internationalization of an iPhone Application I know that its possible to create
I am new to WCF and I want to know if it is possible
Given an array of strings, how do I create another array that has another
I want to know if this is inherently possible: Think of a cloud scenario.
As the title says, I want to know, if possible, how can I create
i don't know if its just possible but i want to create a DataTable

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.