Jump to content

Recommended Posts

I only have a pretty basic understanding of SQL just enough thats gotten me by whenever I needed to use a database for whatever I was writing. I can't seem to find an answer to my specific question via google. I want the value of say column 3 to equal the difference of column 2 - column 1 for every row in the table. I don't have to update a existing database, I'm working on a text-based rpg and working on creating the database.

You don't need that third column. You already know what its values are so there's no point in storing it. It would just mean more data you have to insert and update.

 

SELECT column1, column2, column2 - column1 AS column3, ...

Or just do the math in your code.

$column3 = $row["column2"] - $row["column1"];

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.