Tag Info

New answers tagged

0

try this one, CREATE TABLE TestDiff ( Id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, Val1 INT(11) NOT NULL, Val2 INT(11) NOT NULL, Total INT(11) DEFAULT NULL, PRIMARY KEY (Id) ); INSERT INTO TestDiff (Val1,Val2) VALUES(100,10),(160,30),(140,50),(180,68); UPDATE TestDiff SET Total=(Val1-Val2) ; if u want Update at particular id you can put where ...


0

If this requirement is very important to you, take a look here - calculated fields in MariaDB - never any need to perform calculations - it's all taken care of for you! Although, as has been pointed out, you can always perform the calculations on the fly.


-1

You can try using triggers. Insert val1 and val2 using a stored procedure. Write an "after insert" trigger, to update the third column as difference between the columns val1 and val2.


0

Use this Querry select id,val1,val2, val1-val2 as total from table_name;


0

It is most likely because you have specified the size for INT: ID INT( 11 ). Why do you need it? Try this syntax (add NOT NULL for Primary key): CREATE TABLE IF NOT EXISTS Requests ( ID INT NOT NULL PRIMARY KEY AUTOINCREMENT, Sender VARCHAR( 225 ), Recipient VARCHAR( 225 ) )


3

You should re-evaluate your database design. A relational database is not designed to store arrays in columns. Actually, elements in arrays are "columns" itself. So, what you're trying to do is store multiple columns in a single column... I'd recommend two tables: Persons (PersonId, Name,...) Friends (FriendsId, PersonId, FriendId, Accepted), where both, ...


0

INSERT does not use the WHERE clause, because it adds data to a table, it doesn't filter anything. Your statement would probably look like this: INSERT INTO someTable (someColumn) VALUES ('some value') WHERE otherColumn='other value'; What you probably want is: INSERT INTO someTable (someColumn, otherColumn) VALUES ('some value', 'other value');


0

For the Backend, i'd advice you use MySQL for your database and PHP for the server side scripting. Your PHP would be used to render webservices in JSON or XML to your applications. You might need a very good database programmer to share the burden of work between MySQL and PHP for optimization. He should use functions, and procedures where necessary. For ...


0

I wouldn't suggest using capped collections: they scale badly, as they can't be sharded as of the time of this writing and maybe never. See the according feature request on MongoDB's JIRA. I would use a different approach. Use the users query string as _id. Since the exact query is what identifies your records, there is no need to hash it on the client ...


0

No. There is no possibility to pass for operating system request not to cache file reads for IO done for specific query. You can reduce sysctl parameter vm.swappiness to 1 to make cache recovery more aggressive, but that affects all IO caching in the server.


2

To remove all fields (aside from _id), you can just update with an empty document: <?php $collection->update(array('name' => 'Amy'), array()); ?> That will update the document leaving only the _id field. Note that this won't free up any of the preallocated space for your capped collection.


0

Well, on the mysqli constructor page for the php manual you have several examples on how to deal with connection errors, depending on the PHP version. For example, on the first code snippet, change the die() to if ($mysqli->connect_error) { //try connecting to the backup node $mysqli = new mysqli('backup_node_host', 'my_user', 'my_password', ...


0

1 & 2:use inner join SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name; 3: yes your structure is true


0

column name like '%search%' cannot take advantage of standard BTREE/B+Tree indexes on MyISAM/InnoDB, so you are effectively doing a full table scan. The index is useless, so every single row has to be compared individually. In order to perform string searches in a performant way you have to create a FULLTEXT index and use the operator MATCH ... AGAINST. ...



Top 50 recent answers are included