data updation of a column in sql table based on another column of same table - sql

i have 2 table with four & five column in sql
in 1st table four column like ID - Parant - Position - Assign Id (ID+Position)
in 2nd table five column like assign ID - ID - L1- L2- L3
assign id & ID automatic update from 1st table
L1,L2,L3 based on assign id & ID column
i want a query for L1 column for update data like this procedure
find (ID+Left) in assign Id column and if match with records then copy record from ID column whose matched in assign Id and paste in L1 column
plz help me

You can use update with join to update table column.
Example: http://sqlfiddle.com/#!2/07622

Related

SQL Join Problem Table two has more as one Record for ID

I have a SQL query problem.
i have two tables.
Table One UINT ID and same Fields
Table Two have Records with ID from the first Table. but more than one record for the ID.
Table Two:
ID=1 StringField1= "Hello" Stringfield2="World"
ID=1 StringField1= "Auto" Stringfield2="Street"
Is there a way to construct a query in such a way that I get a record of the form
1,Hello,World,Auto,Street,....etc.
Lot of Thanks.
Winfried
Have you a solution for this Problem?
Hello.
In Table 1 as the main Table is the field C_URI. This Field is the Key for the Table 2 , Field FK_Workitem. In Table 1 is one Record for the Key.
In Table 2 are the Costumer Fields with teh Fieldname and Feild value. in our Example:
Field 1 -> Name variationType value -> mandfeature
Field2 -> Name swe1_coverage value -> started
I now want to make a query in which I only have one record
C_URI, variationType value, swi_coverage value.
What must i do?
Select Statement
Output

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

Oracle PL/SQL Query, Adding new column through looping

I have a table in excel which is called the test table:
I need to create an additional column called level in the table through the following steps.
Whenever 'parent' column is equal to 'EEP', Check the values in the location column. In this table, the location column has only A under the filter of EEP for parent column. Now Assign value of 1 in the level column
Now check value A under parent column. Values under location are B,N,S. Assign 2 under level column
Now check B,N,S under parent column. Values under location are C,D,Q,U,V. Assign 3 under level column
Now check C,D,Q,U,V under parent column. values corresponding to location are R, M. Assign 4 under level column.
My final table should look something like this.
I need to write a query in Oracle SQL to do the same for all rows in the parent column adding one in the level column after every iteration. This data is just a test data, the original data has more than 2.6 million rows.
You need a simple connect by clause -
CREATE TABLE NEW_TABLE AS
SELECT C.LOCATION, C.PARENT, LEVEL
FROM CTE C
START WITH PARENT = 'EEP'
CONNECT BY PRIOR LOCATION = PARENT;
Here is the fiddle

SQL Server : how to delete specific rows data with where condition in column?

I have a table with some columns and rows. I want to delete some rows contain specific data at specific row.
Ex: the table name is EXAM
I want to delete row 1 and row 3 when input condition string is C.
I did with the statement:
DELETE FROM EXAM
WHERE Comumn2 = 'C'
but only deleted Row 3.
To match rows which contain a specific value, use LIKE instead of =:
DELETE FROM EXAM WHERE Column2 LIKE '%C%'
Another Way of doing it by using CharIndex
DELETE FROM EXAM WHERE CHARINDEX('C',Column2)>0