add value to column after select - sql

I have a button the executes a SELECT statement. When that button is clicked I need a query that counts + 1 in the column records.
So records can be 2. When I click the button + 1 should be added, so the new number in the column is 3. I am not quite sure how to do that. Is it modify column I have to use here?
ALTER stores MODIFY COLUMN records INT COUNT + 1;

First you have to stock the int you get in your first select query, I dont know which language you use but something like that
int result = "SELECT records FROM stores"
Then you increment your result
result++;
And you update the column with the new value
UPDATE stores SET records = " + result

Related

How can i increase (update) a cell in a SQL Table? in a query

I have a question, currently i have a table named "OrdersAndSerials".
In one of their columns is named Delivery, then i need to take a value of this Column, and and add a value.
Example.
In the green box of this row, the valor of Delivery is 123, but i need to add '10' of this cell.
The final result must be 133.
SQL Table
you can easily perform this operation using UPDATE statement.
Assuming you need to add 10 to original delivery value, and HUSerialBox is the primary key in this table.
update OrdersAndSerials set delivery = delivery + 10 where HUSerialBox = '140933vv';
Assuming that the Delivery column is of the datatype int you can use the UPDATE statement to change the value of the cell.
UPDATE OrdersAndSerials
SET Delivery = Delivery + 10 /* or whatever value you want to change it by */
WHERE HUSerialBox = '140933vv';

How to add bulk values in column using DB Browser SQLite

I have a table that contain two columns. One column "rewords" contain 12186 words. and the other column named "ID" is the column that I newly created so it is empty. I want to add numbers against the rewords column. numbers from 1, 2, 3, to 12186. i tried to use primary key not null operation but it disturbs the order and its sequence becomes unpredictable like 1,2,6,10,7,8,19....
If I manually type 1,2,3 in the fields, then it will be too time-consuming and effortful. Following is the screenshot of what I desire. I want that I could have typing from 1 to 12186 in the fields of ID column.
I also tried the following function in the query tab, but it doesn't work and gives error that "near "for": syntax error: for"
for(int i = 1; i<=12186; i++){
UPDATE tbl SET ID = i WHERE index = i;
}
you don't need the loop you can do this with a single query
UPDATE tbl
SET ID = index
WHERE index <= 12186;
otherwise if you have not a column index .. you need an autoincrement value in you id column .. you should
You can do it with SQLite Expert Personal 4:
1) Select the table and then go to "Design" tab > "Columns" tab.
2) Click select the ID column name, and type INTEGER and Not Null > Ok.
3) Go to "Primary Key" tab in "Desgin tab".
Click "Add" and select the column ID. Check the "Autoincrement" box.
4) Click "Apply" on the right bottom part of the window.

This Oracle SQL doesn't work in Oracle Apex

if :p6_internal_id is null then
INSERT INTO table
(
id,
account
)
values
(
tseq_id.nextval,
:p6_account,
);
else
update table set "all columns" where id = :p6_internal_id;
end if ;
This says
ORA-00927: missing equal sign
for the update set "all columns" line.
I don't know how to fix this. How do I set the value of all the columns where id is what I enter?
Based on your comments, you just need to change that line to:
update table set account = :p6_account where id = :p6_internal_id;
You don't need to set the id column to :p6_internal_id as you know it already has that value - since you're using it in the where clause.
There is no magic value of '"all columns"' that would allow every column to be updated at once, not least because you need to supply a value that corresponds to every column anyway, and in the right order.
If you have multiple columns to set then you have to list them all explicitly, with each column/value pair separated by commas; e.g. with a few made-up columns and bind variables:
update table set account = :p6_account,
name = :p6_name,
amount := p6_amount
where id = :p6_internal_id;
You can see the required syntax in the documentation.

Duplicate a column into a temporary table then convert data

Is there a way to duplicate a column from a current database table (copy all the column contents from table to a temporary table), Then
Convert the string value in the column and increment it by 1, then
Put all those values in a form of a string back into it's original table?
So pseudocode would look like:
copy column1 from tblReal into tmpcolumn in tblTemp (set tmpcolumn1 as nvarchar(265))
update tblTemp
set tmpcolumn1 = 'TESTDATA' + 1
copy tbmpcolumn1 from tblTemp into column1 in tblReal
So actually you want to change a string column, which holds actually a number, by incrementing its value by 1. Why would you need three steps for that? Just do an update statement on the column immediatly. I don't see why you need intermediate tables.
UPDATE tblReal SET column1 = column1 + 1
Piece of cake. You can use the cast function to transform the varchar to a number and back again in the update statement.

How to INSERT INTO a MySQL table using ON DUPLICATE KEY UPDATE?

How to INSERT INTO a MySQL table using ON DUPLICATE KEY UPDATE so that if the row already exits one of the columns of the row gets it value plus 1? So, if I have two columns titled ip and count, the count column contains 1 in the first place and increases its value on every next UPDATE. Can we do that in one single statement?
INSERT INTO table(ip,count) VALUES(ip,0)
ON DUPLICATE KEY UPDATE count = count+1
I think it should simply work.
Given two columns, ip and count the query would look like this:
$ip = "10.1.1.1";
$query = "insert into `my_table` (`ip`, `count`) values ('$ip', 1)
on duplicate key update count = count + 1";
This will start with a count of 1 for each new IP, and increment the existing count if it already exists.