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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:59:38+00:00 2026-05-27T04:59:38+00:00

The Setup I have two tables, USERS and PETS . each user has an

  • 0

The Setup


I have two tables, USERS and PETS.

each user has an ID, a NAME, and a flag HAS_PETS, which is 1 if the user owns at least one pet, and 0 otherwise.

Each pet has an ID, a NAME, and an OWNER_ID. Here is the creation script:

create table USERS(
ID NUMBER(*,0),
NAME VARCHAR2(50 BYTE),
HAS_PETS NUMBER(1,0),
CONSTRAINT "XPKUSERS" PRIMARY KEY ("ID")
);

create table PETS(
ID NUMBER(*,0),
NAME VARCHAR2(50 BYTE),
OWNER_ID NUMBER(*,0),
CONSTRAINT "XPKPETS" PRIMARY KEY ("ID")
);

insert into USERS values(0, 'Alice', 0);
insert into USERS values(1, 'Bob', 1);
insert into USERS values(2, 'Carol', 0);

insert into PETS values(0, 'Fido', 1);
insert into PETS values(1, 'Spot', 1);
insert into PETS values(2, 'Xerxes', 2);

The Problem


At one point, many pets were added to PETS, but the OWNER table’s HAS_PETS flag was not updated. In the sample data above, Carol owns Xerxes, but her flag is 0.

I want to write a statement which will set HAS_PETS to true if the owner has a pet. With the above data, it should set Carol’s HAS_PETS flag to 1.
I tried this:

update (
select * 
from USERS a join PETS b 
on a.HAS_PETS = 0 and a.ID = b.OWNER_ID
)
set HAS_PETS = 1 

but it gives an error, cannot modify a column which maps to a non key-preserved table. Oracle recommends that I Modify the underlying base tables directly, but I can’t identify which rows need updating unless I do this join.

Googling around prompted me to try this alternative syntax:

update a
set a.HAS_PETS = 1
from USERS a join PETS b 
on a.HAS_PETS = 0 and a.ID = b.OWNER_ID

but it gives an error, SQL command not properly ended, and Wikipedia says “Some databases allow the non-standard use of the FROM clause”, leading me to believe this isn’t supported by Oracle.

The Questions

  • What is the meaning of the first error? HAS_PETS belongs to USERS, which has a primary key. I don’t see any non key-preserved tables here.
  • How can I modify my statement so that it executes the way I expect it to?
  • 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-27T04:59:39+00:00Added an answer on May 27, 2026 at 4:59 am

    You could try

    UPDATE a SET HAS_PETS = 1
    WHERE ID IN 
        (SELECT DISTINCT OWNER_ID FROM b) p
    

    It could be faster using your additional condition (thanks to @jadarnel27 to noticed that)

    UPDATE a SET HAS_PETS = 1
    WHERE HAS_PETS = 0 
      AND ID IN 
        (SELECT DISTINCT OWNER_ID FROM b) p
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: tblBadge ------- ID Name tblBadgeUsers ------- BadgeID UserID A user
I have two tables, users and images which need to be joined. there is
I have two models Users and Roles . I have setup a many to
I have two tables set up in a many-to-many relationship: Incidents and Users. When
I am trying to setup a simple database in which I have a user
I have two tables: Avatars: Id | UserId | Name | Size ----------------------------------------------- 1
I have these two tables setup and the below query running. The problem is
I have used the standard user tables that ASP.net setup and I'm looking to
I'm trying to set up a project using hibernate.I have two tables : Users
I have two tables, GAMES and USERS set up with the following fields: tblGAMES-->

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.