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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:29:39+00:00 2026-05-20T01:29:39+00:00

I have the following query and I’m trying to update table1 with the Total

  • 0

I have the following query and I’m trying to update table1 with the Total amount.
Is there anyway to do this in 1 step?

select e.id
     , p.id
     , case  
         when count(distinct e.item) = 1 then 100
         when count(distinct e.item) = 2 then 150
         when count(distinct e.item) = 3 then 200
         when count(distinct e.item) = 4 then 225
         when count(distinct e.item) = 5 then 275
         when count(distinct e.item) = 6 then 325
         when count(distinct e.item) = 7 then 375
         when count(distinct e.item) = 8 then 450
         when count(distinct e.item) = 8 then 470
       end as TotalPay
  from table1 p 
  join table2 e on e.id = '111111'
               and p.id=e.itemid
group by e.id, p.id
  • 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-20T01:29:40+00:00Added an answer on May 20, 2026 at 1:29 am

    Use:

    UPDATE TABLE1
       SET total = (SELECT CASE
                             WHEN COUNT(DISTINCT t2.item) = 1 THEN 100
                             WHEN COUNT(DISTINCT t2.item) = 2 THEN 150
                             WHEN COUNT(DISTINCT t2.item) = 3 THEN 200
                             WHEN COUNT(DISTINCT t2.item) = 4 THEN 225
                             WHEN COUNT(DISTINCT t2.item) = 5 THEN 275
                             WHEN COUNT(DISTINCT t2.item) = 6 THEN 325
                             WHEN COUNT(DISTINCT t2.item) = 7 THEN 375
                             WHEN COUNT(DISTINCT t2.item) = 8 THEN 450
                             WHEN COUNT(DISTINCT t2.item) = 9 THEN 470
                           END
                      FROM TABLE2 t2
                     WHERE t2.itemid = id
                       AND t2.id = '111111'
                  GROUP BY t2.id, t2.itemid)
     WHERE EXISTS(SELECT NULL
                    FROM TABLE2 t
                   WHERE t.itemid = id
                     AND t.id = '111111')
    
    • The WHERE clause is necessary, otherwise all the TABLE1 rows will be processed. Those who don’t have related TABLE2 rows, would’ve been updated to NULL
    • Oracle (IME, up to 10g) doesn’t support JOINs in an UPDATE clause like MySQL & SQL Server — you have to use a subquery (correlated in this example). It also doesn’t allow you to define a table alias for the table being updated, so when a table alias is omitted like you see in the example — the column is coming from the table without an alias (the one being updated)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following query select * from table1 if table1 contains text type column/columns
i have following query working.. select count(id) , case when age < 0 then
I have following query working : SELECT COUNT(id), AgeRange FROM ( select id, case
I have following query in my project, $values = array(test=>value) $this->_db->update(tablename,$values,array('id = ?'=> $data['id'],'wid
I have following query Select a,b,c, case totalcount when 0 then 0 else abcd/totalcount
I have this following query: SELECT a.rank AS rank, concat( m.prenom, ' ', m.nom
I have following SQL query but this is not quite what I want: SELECT
I have following query: $query=SELECT language_value, votes, user_id FROM labels WHERE approved=1 AND label_value=.
I have following query , select * from process where name like 'abc'; now
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER

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.