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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:41:42+00:00 2026-05-29T08:41:42+00:00

I have 3 tables: tbl_indicator grp_nbr, sect_nbr, indicat 1 100 p 2 101 s

  • 0

I have 3 tables:

tbl_indicator

grp_nbr,   sect_nbr,   indicat  
1             100          p  
2             101          s
tbl_group 

grp_id,    grp_nbr,    sect_nbr,     indicat  
333         1              100           a  
555         1              100           p  
444         2              101           s
222         2              101           y

Here (in tbl_group) grp_id is Primary Key

tbl_order

order_id,       grp_id
5000              333
5001              555
5002              555
5003              555
5004              444
5005              444
5006              222

Here (in tbl_order) grp_id is a Foreign Key to grp_id in tbl_group.

In table tbl_indiactor, for one set of grp_nbr and sect_nbr there is an indicat, for the same set of grp_nbr and sect_nbr there is a correct indicat(555,1, 100, p) and a junk indicat(333, 1, 100, a) in table tbl_group, but both these grp_id s(333, 555) are present in table tbl_orders.

Now i need to update tbl_order table in such a way that the junk grp_id s should be replaced with correct grp_id s

The output should like:

tbl_orders

order_id,       grp_id
5000              555
5001              555
5002              555
5003              555
5004              444
5005              444
5006              444

here is a small change

tbl_indicator

grp_nbr, sect_nbr, indicat
01 100 p
02 101 s
tbl_group

grp_id, grp_nbr, sect_nbr, indicat
333 01 100 a
555 01 100 p
444 02 101 s
222 2 101 y
Here (in tbl_group) grp_id is Primary Key

the junk data(indicat) in group table (222, 22, 101, y) the grp_nbr has one character length but the grp_nbr in tbl_indicat has two character length…
how can we handle this??

  • 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-29T08:41:42+00:00Added an answer on May 29, 2026 at 8:41 am

    First, figure out which records need to be updated:

    select *
    from tbl_order o
    inner join tbl_group g on
        g.grp_id = o.grp_id
    inner join tbl_indicator i on
        i.grp_nbr = g.grp_nbr
        and i.sect_nbr = g.sect_nbr
    where
        g.indicat != i.indicat
    

    Now, modify the query to update those records with the correct grp_id. Notice that I’ve added an extra join to the tbl_group table with an alias of “g2”. This will be the correct group.

    update o set
        o.grp_id = g2.grp_id
    from tbl_order o
    inner join tbl_group g on
        g.grp_id = o.grp_id
    inner join tbl_indicator i on
        i.grp_nbr = g.grp_nbr
        and i.sect_nbr = g.sect_nbr
    inner join tbl_group g2 on
        g2.grp_nbr = i.grp_nbr
        and g2.sect_nbr = i.sect_nbr
        and g2.indicat = i.indicat
    where
        g.indicat != i.indicat
    

    Note that due to the inner join on tbl_group g2, the records will not be updated if there does not exist any tbl_group record where indicat matches the indicat value of its associated tbl_indicator record.

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

Sidebar

Related Questions

I have the following tables: 1) TBL (ID, Data, LastUpdated, DateCreated) 2) TBL_LOG(Log_ID, LogCreateDate,
I have 3 tables with values like below **tbl_product** recID pID price colour 1
I have two tables, tbl_foo and tbl_bar , and I want to join these
I have 10 tables in my database(MySQL). two of them is given below tbl_state
android noob... I have two tables, with a one to many relationship between country_tbl
I have two tables tbl_a and tbl_b and their fields are tbl_a ----- a_id
I have done PRAGMA foreign_keys=ON; and it's still not working. Tables: tbl_one { user_id
i have 3 tables structure is below tbl_login login_id | login_name 1 | keshav
I have 5 tables and trying to Join into 1 but I am getting
I have two tables : Product and ProductRateDetail. The parent table is Product. I

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.