SQL: Update values in column based on another - sql

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

Related

There are multiple column in my table and I want to skip one column if value is null for that one particular column in oracle update query?

There are multiple column in my table and I want to skip one column if value is null for that one particular column and all other columns should be updated with there respective value in oracle update query.
Is there any simple way to do this ?
Example:
Let me explain my problem with example:
I am using merge query like below :
merge into table_X on (condition )
WHEN MATCHED THEN
UPDATE SET COLUMN_1=VALUE1 , COLUMN_2=VALUE_2,........
WHEN NOT MATCHED THEN
INSERT ( COLUMN_1,COLUMN_2...) VALUES (VALUE_1,VALUE_2);
Now in update statement I want to skip the update for one column suppose COLUMN_2 if its value is null , but all other column should be updated . Basically I want to preserve the existing value when null is coming .

Insert a column from output of a query into already populated postgresql database without adding new rows

I have a table named comments_live which has 4 fields and some 24000 entries. I want to add another field which is the output of a select query. The query is like this:
INSERT INTO comments_live SELECT SUBSTR(record,1, POSITION(' ' IN record)) AS project_id FROM comments_live;
What this query is doing is it's appending the result of the SELECT query to the table. I want the 'project_id' field to be appended to the existing 24000 rows. i.e. The above query should not add those extra rows to the table.
Any help would be appreciated.
PS: I tried adding a empty column 'project_id' to the table first and then executing the query, still I'm getting the same result.
I conclude from your code example that you want to add a column whose content is the substring from the column RECORD. If you succeeded in adding the empty column, then you just need code like the following:
update comments_live
set project_id=substr(record,1,[...])

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

Replacing values in a table with a value from another table (complicated)

I have a table that contains various values in a single cell. I want to replace part of the value in that cell that matches with a value from another table.
Researched extensively online but could not find a lot of information regarding it.
For example - I have the following table
If part of the value in table 1 matches with table 2, I want it to be replaced with the value from table 2 (second column).
For example in table 1 - value "www.portal.com/kav1232" matches with "www.portal.com/kav1232" in table 2 then the value in the cell from table 1 is replaced with "www.new1.com" but rest of the content from the cell remains the same.

Populate column using single cell value from a different column with SQL

I am trying to populate an entire date column in an Access database with a single date value for when the data was collected. The date value is contained in each table, but I want a separate field containing the date in each row. When I used this code it only populated the one row in my new field (sampling_date) where the date is located. The date is located in the sampling_info field on row 4
UPDATE table SET [sampling_date]=[sampling_info] WHERE [point]=4;
Thanks for any help,
Paul
It sounds to me like this is what you're after
UPDATE [table] SET sampling_date = DLookup("sampling_info","table","point=4")