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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:02:20+00:00 2026-06-12T09:02:20+00:00

I have a unique column. I also have a known set of elements that

  • 0

I have a unique column. I also have a known set of elements that are possible values for the column. I need to know which of the possible values are not already in the table, and as such, are suitable for insertion.

Is this possible with SQL or is post processing required?

Currently, I am using the “in” operator to select all rows where the column value equals an element in my set. Then I remove all matched elements from my set via post processing.

  • 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-12T09:02:21+00:00Added an answer on June 12, 2026 at 9:02 am

    Stick the allowed values in a temporary table allowed, then use a subquery using NOT IN:

    SELECT *
    FROM allowed
    WHERE allowed.val NOT IN (
        SELECT maintable.val
    )
    

    Some DBs will allow you to build up a table “in-place”, instead of having to create a separate table. E.g. in PostgreSQL (any version):

    SELECT *
    FROM (
        SELECT 'foo'
        UNION ALL SELECT 'bar'
        UNION ALL SELECT 'baz'    -- etc.
    ) inplace_allowed
    WHERE inplace_allowed.val NOT IN (
        SELECT maintable.val
    )
    

    More modern versions of PostgreSQL (and perhaps other DBs) will let you use the slightly nicer VALUES syntax to do the same thing.

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

Sidebar

Related Questions

I know that using the following codes will make each column have unique values,
I have a temporary table that I'm using and I have a unique column,
I have a tasks table with a priority column, which has a unique constraint.
I have a database table with a column called 'symbol', that is unique via
Is it possible to use a DB sequence for some column that is not
Possible Duplicate: How do I create unique constraint that also allows nulls in sql
I have SQL Server 2008 R2 and I want to set a unique column.
I have a, probably unique situation in which I need to use a single
Does each column of a table in SQL Server have a unique id? I've
I'm using Hibernate 4.0.1.Final. I have a table with a unique constraint column …

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.