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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:34:19+00:00 2026-05-29T07:34:19+00:00

I have an Oracle table called users, with columns name, location, organization, valid_from, valid_to,

  • 0

I have an Oracle table called users, with columns

name, location, organization, valid_from, valid_to, active.

What I am trying to do is:
if there are two records with same name, location, organization but with valid_to, valid_from intervals overlapping, to set the active status of each record to ‘NOK’.
Here’s how I am trying to do it :

UPDATE table SET active= 'NOK' 
WHERE 
(name, location, organization) IN (
     SELECT t1.name, t1.location, t1.organization   
     FROM table t1
     WHERE (valid_from > t1.valid_from and valid_to < t1.valid_to )
      GROUP BY t1.name, t1.location, t1.organization   
      HAVING COUNT(*) > 1) ;

But this doesn’t seem to do what I desire. What am I doing wrong?

  • 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-29T07:34:22+00:00Added an answer on May 29, 2026 at 7:34 am

    The WHERE clause in your subquery will be FALSE for all rows because you didn’t specify a table alias for some columns:

    (valid_from > t1.valid_from and valid_to < t1.valid_to )
    

    will be assumed to mean

    (t1.valid_from > t1.valid_from and t1.valid_to < t1.valid_to )
    

    I think this does what you want:

    UPDATE table t1 SET active = 'NOK' 
    WHERE EXISTS 
    ( SELECT 1
      FROM   table t2
      WHERE  t2.name = t1.name
      AND    t2.location = t1.location
      AND    t2.organization = t1.organization
      AND    t1.valid_from <= t2.valid_to
      AND    t2.valid_from <= t1.valid_to
      AND    t1.ROWID != t2.ROWID
    );
    

    However, if valid_from or valid_to can be null then you need to handle that case also.

    (The ROWID comparison is to prevent tows matching with themselves!)

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

Sidebar

Related Questions

I have a table in Oracle called quotes with two columns: date and value
I have a oracle table called: create table InsertHere( generate_id varchar2(10), name varchar2(100) );
In my oracle database I have table called PERSON with columns code, surname, forename.
In Oracle, I have a table called MyTable. This table has columns 'A' and
In my Oracle database, I have a table called Customers. There are fields for
So i'm having this problem. I have two tables (Oracle), one is called Destination
In our Oracle database we have a table called RULES, with a field called
Oracle 10g DB. I have a table called s_contact . This table has a
Given: Oracle 10.2g is the database I have a table called emp. emp has
I have created an Oracle table with an indexed varchar2 column, called 'ID'. A

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.