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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:03:31+00:00 2026-06-01T11:03:31+00:00

I need help extending a functional update query that performs calculations on one record

  • 0

I need help extending a functional update query that performs calculations on one record to be able to perform calculations not only on one record in the database, but on all records associated with a particular user #.

Functionally, I need to extend an “edit this record” to “reevaluate all records of user#?”

Current calculations make use of 3 tables, sum a column, divide by the sum of another, and then creates a variable from that result(there are two columns summed separately to create two variables). Then I have a simple UPDATE query to update the record with the values of those variables. Each record has different values, and the sums will be different for every id#
@lastid is the unique record id.(allinfsds.id1)
I need to have the calculations done on all records that = a particular owners id (allinfsds.own_id)[i.e. WHERE allinfsds.own_id= usernum]

Any ideas???
Thanks ahead of time,
Nat

    CREATE TABLE `allingred` (
  `id6` int(8) NOT NULL auto_increment,
  `usernum` varchar(255) default NULL,
  `fsdsnum` int(8) unsigned zerofill NOT NULL,
  `mfdfsds` varchar(255) default NULL,
  `maybe` decimal(2,1) NOT NULL default '1.0',
  `amount` float(10,2) default NULL,
  `unit` int(6) default NULL,
  `name` varchar(255) default NULL,
  `wgt` int(9) NOT NULL,
  PRIMARY KEY  (`id6`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=38 ;

    CREATE TABLE `weight` (
  `NDB_No2` int(8) unsigned zerofill NOT NULL,
  `Seq` smallint(6) NOT NULL,
  `amt2` decimal(5,3) NOT NULL,
  `Msre_Desc` varchar(80) NOT NULL,
  `Gm_Wgt` decimal(7,1) NOT NULL,
  `Num_Data_Pts` tinyint(4) default NULL,
  `Std_Dev` decimal(7,1) default NULL,
  `uni` int(7) NOT NULL auto_increment,
  PRIMARY KEY  (`uni`),
  KEY `fb_join_NDB_No2_INDEX` (`NDB_No2`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=21731 ;

    CREATE TABLE `allinnot2` (
  `NDB_No` int(8) unsigned zerofill NOT NULL,
  `Water` decimal(10,2) default NULL,
  `Energ_Kcal` decimal(10,0) default NULL

    CREATE TABLE `allinfsds` (
  `id1` int(8) unsigned zerofill NOT NULL,
  `own_id` int(11) NOT NULL
  UNIQUE KEY `id` (`id1`),
  KEY `fb_groupbyorder_item_number_INDEX` (`item_number`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


    SET @cal = (SELECT SUM( Energ_Kcal * allingred.amount * Gm_Wgt) / SUM( allingred.amount * Gm_Wgt ) AS nut100
FROM  `allingred` 
LEFT JOIN weight ON allingred.unit = weight.uni
LEFT JOIN allinnot2 ON allingred.mfdfsds = allinnot2.NDB_No
LEFT JOIN allinfsds ON allingred.fsdsnum = allinfsds.own_id
WHERE fsdsnum = @lastid)

SET @prot = (SELECT SUM(Protein * allingred.amount * Gm_Wgt) / SUM( allingred.amount * Gm_Wgt ) AS nut100
FROM  `allingred` 
LEFT JOIN weight ON allingred.unit = weight.uni
LEFT JOIN allinnot2 ON allingred.mfdfsds = allinnot2.NDB_No
WHERE fsdsnum = @lastid)

UPDATE `allinnot2` SET
  `Energ_Kcal` = @cal,
  `Protein` = @prot
WHERE `NDB_No` = @lastid
  • 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-01T11:03:33+00:00Added an answer on June 1, 2026 at 11:03 am

    How to update multiple tuples at once

    If you have a list of Ids you want to update, use

    UPDATE `myTable` SET `myColumn` = 'newValue' 
    WHERE `userId` IN (
        /*list of relevant Ids for instance: */ 15, 20, 63, 987
    )
    

    or if you dont have this list, but you can query the database for this list, use

    UPDATE `myTable` SET `myColumn` = 'newValue' 
    WHERE `userId` IN (
        SELECT `userId` FROM `myOtherTable` WHERE `relevantColumn` = 'value'
    )
    

    Beware that you are not allowed to use the same table as both the update target and source of ids in the subselect, so myTable != myOtherTable.

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

Sidebar

Related Questions

need help/guide for sql select query, I have 2 table stock and stock_history, in
I need some help with a MySQL query I'm working on. I have data
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
Need help writing a script downloads data from google insight using c# this is
need help regarding USSD Gateway. I have to develop an app, which will directly
need help in error in database pivot. i have table tamed table_score like below:
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help understanding some C++ operator overload statements. The class is declared like
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
I need help getting my head around the difference between my current OOP notion

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.