Facebook  Twitter 

SMFHacks.com

+- +-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 11916
Latest: aire
New This Month: 17
New This Week: 5
New Today: 0
Stats
Total Posts: 37897
Total Topics: 6668
Most Online Today: 91
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 73
Total: 73

Author Topic: Complicated MySQL Query  (Read 806 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • SMF Store Customer
  • Hero Member
  • *****
  • Posts: 579
    • View Profile
    • Biology Forums - For All Your Science Needs
Complicated MySQL Query
« on: January 10, 2017, 11:30:26 pm »
Let's pretend we have a table:

ID      col1      col2
1      33      2
2      52      78

I want to sum col1 and col2 and replace the value of col1 with that sum:

ID      col1              col2
1      35                         2
2      130                      78

Could you tell me the query I'd use to do this

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 14031
    • View Profile
Re: Complicated MySQL Query
« Reply #1 on: January 11, 2017, 08:06:02 am »
Backup first
Something like
Update tablename set col1 =(COL1 + COL2)
Get your Forum Ranked! at http://www.forumrankings.net - find out how your forum compares with others! Also contests/promotions for verified sites.

Offline shuban

  • SMF Store Customer
  • Hero Member
  • *****
  • Posts: 579
    • View Profile
    • Biology Forums - For All Your Science Needs
Re: Complicated MySQL Query
« Reply #2 on: January 11, 2017, 02:52:03 pm »
Worked, thanks

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
2441 Views
Last post January 31, 2008, 05:28:27 pm
by SMFHacks
0 Replies
1390 Views
Last post October 12, 2010, 05:49:10 pm
by mxcape21
4 Replies
2609 Views
Last post July 11, 2016, 12:50:54 pm
by shuban
1 Replies
1791 Views
Last post August 17, 2016, 06:12:18 pm
by SMFHacks
12 Replies
887 Views
Last post February 10, 2017, 08:56:57 am
by GeorG

+- Recent Topics

Error 500 in index.php?action=gallery;sa=add2 by nend
April 28, 2017, 01:31:50 pm

Custom Fields in Gallery by bknapp
April 26, 2017, 07:03:07 pm

With .htaccess, how do I redirect an action to another action by nend
April 26, 2017, 10:29:51 am

RSS Feed killed my forum by hippieboy123
April 18, 2017, 07:39:26 am

Is there a converter than converts all files found in topics of a specific board by SMFHacks
April 13, 2017, 02:46:18 pm

Sidebar Image width by hippieboy123
April 12, 2017, 01:32:00 pm

I run a Custom Theme and have many Test Failed - What to do? by SMFHacks
April 11, 2017, 05:12:15 pm

Daughter menus by Labradoodle-360
April 08, 2017, 05:37:22 pm

Lost my copyright removal when I converted forum to SSL by Nova
April 08, 2017, 01:19:50 pm

Newsletter Pro errors in log by SMFHacks
April 03, 2017, 04:54:40 pm

Powered by EzPortal