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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:08:26+00:00 2026-06-15T18:08:26+00:00

I have two tables I want to update table b in column bcnt by

  • 0

I have two tables I want to update table b in column bcnt by the value that in column acnt in table A where the worlds column in table A match words column in table B, and id in table B match id in table A.

create table a 
( 
    id number(9),
    words varchar2(2), 
    acnt number(9)
);

insert into a values(1,'Cairo',20);
insert into a values(1,'UK',10);
insert into a values(2,'KL',2);
insert into a values(2,'Cairo',2);
insert into a values(2,'London',30);
insert into a values(3,'Cairo',5);
insert into a values(4,'KSA',15);

create table b 
(
     id number(2), 
     words varchar2(20), 
     bcnt number
);

insert into b values(1,'Cairo',null);
insert into b values(1,'UK',null);
insert into b values(2,'KL',null);
insert into b  values(2,'Cairo',null);
insert into b values(3,'Cairo',null);
insert into b values(4,'KSA',null);

I used this SQL code but it is not correct.

update b 
set bcnt = (select acnt 
            from a 
            where a.id = b.id and a.words = b.words);

Expected results:

1   cairo  20
1   uk     10
2    kl     2
2   cairo   5 
4   ksa     12

The SQL shows me the following

SQL> /

        ID WORDS                      BCNT
---------- -------------------- ----------
         1 Cairo
         1 UK                           10
         2 KL                            2
         2 Cairo
         3 Cairo
         4 KSA

6 rows selected.

SQL>

  • 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-15T18:08:27+00:00Added an answer on June 15, 2026 at 6:08 pm

    Is the problem that your SQL uses word instead of words as in the table definition?

    update b
        set bcnt=(select acnt from a where a.id=b.id and a.words=b.words );
    

    Also, your data types are not correct in the two tables. Your create table statements should be consistent:

    create table a (id number(9),words varchar2(20), acnt number);
    create table b (id number(9), words varchar2(20), bcnt number);
    

    What is happening is that the values longer than 2 characters in the first table are being truncated to two characters. So, instead of ‘Cairo’ the value is ‘Ca’ (to fit in varchar2(2)). As a result, you have no match in the join.

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

Sidebar

Related Questions

I have two tables nol_art and #tmpIzm I want to update nol_art with value
I have two tables that I want to join together. Table1 Year, ID, Theme,
I have two tables and I want to display only the child ID that
I have two tables Loan(Parent Table) and Receipt(Child table)what i want to do is
I have two tables and two buttons. I want table-1 to be in the
I have two tables that are very slightly different. Table A has 4 columns,
I have two already-existing tables which look (in part) roughly like this: CREATE TABLE
I have two tables with the same column anomaly_id . I want to copy
i have two tables CREATE TABLE IF NOT EXISTS `user` ( `user_id` int(20) NOT
I have two tables. Table user : CREATE TABLE IF NOT EXISTS `user` (

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.