How to replace values in different columns is same sql table - sql

What would the script be if I wanted to update column b with different values for current values of column A? So in column values currently have different values and we need the final result to be as per below.
P.e.
Column(A) Column(B)
0440 A
04470 A
045102 A
030532 B
03580 B
03240 C
etc.
Thank you.

Related

SQL: Update values in column based on another

I have an SQL table, 1 column has stuff written in this way 'AAAA-BB-CC', and the second one has values written in the following format 'XXXX YYYYYY'
How can I make a SQL query that would make the 2nd column 'AAAA-BB-CC YYYYYY'. Basically I want to take the value in column 1 + the 2nd part of the value in column 2 and update column 2 to have this new value

insert and update from table a to table b by combining 2 column from table a in postgres

I have 2 tables name Table A and Table B
"Table A has 10 columns named ta1, ta2, ta3...ta10"
"Table b has 2 columns name id (PK,AI) and tb1"
My requirement is to combine "ta3" and "ta4" from table A initially,
or it will check for the "tb1" column whether any same data is available, if available do nothing else insert the new data.(if a new row is added in the ta3 or ta4, it should be added to the 2nd table column named tb1)
I have checked other functions in the for combining the data from ta3 and ta4 by using the "unnest" function, but if I use that, I'm getting stuck in the insert, as it will insert on each query rather than checking whether any data is there or not.
any solution on this legends.
simply I just want to combine 2 column from 1st table and store it in a column on 2nd table, but in 2nd table's column it should be only distinct values taken from both of those 1st table columns. this should automatically check for the values in the column of 2nd table and compare that with the new one and if there is change the insert else neglect. I hope my question is clear.
Table1
Table 2
new table-1
Expected table-2

Postgres SQL - copy data from one column to another and if null from another one

I need a help with some challenge
How can I (using sql script for PostgreSQL) copy data from column A to B if A is NULL and if B is null as well copy data from column C?
So if A is null copy data from B but if B is also Null copy from column C.
All data are in same table.
Is it possible?
Perhaps COALESCE is what you want here with an update:
UPDATE yourTable
SET A = COALESCE(B, C)
WHERE A IS NULL;
This logic would update records with a NULL value for A with values from B, or if the B values also be NULL, from C.

Compare two column and fetch data from another column in same table

I want to compare Column A and Column C. And want to fetch data from Column B. All are in same table.But when I searched with 'C' column data I found diferent date. I need that date.
select b from table where a=c;
in this case a and c columns having the same data type. i.e character varying
Try this
Select date(b) from table name where a=c
As per you data it will return the null output
All columns in the table were value except column c
But you are indicated column c return date. Check it

Insert null in one column on two columns same value in Oracle sql

i have inserted value from one table to another and i want to check if two columns values are same in a row insert null in one column of another table(table in which i am inserting values. In my example it is table1).
My existing query is given as follows how should i convert it according to my requirement.
INSERT INTO table1 (date1,date2)
SELECT substr(numtodsinterval(MAX(date1)-MIN(date2),'day'),
12,8)
FROM table2 where ....;