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.
Related
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
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
I am working on a script using SQLite where there is a flux in the number of columns that are available to be inserted into a table I am creating to later do a join on.
The table I am created to insert the data into has 97 columns, the data coming in from my feed can range from around 80 all the way up to that 97th column.
The error I get is SQLITE_ERROR: table allPositionsTable has 97 columns but 80 values were supplied and is the one I am trying to avoid by figuring out a way where this doesn't happen.
Are there any workarounds or tricks I can use to have SQLite function so that it will always include the columns where there is no data for them or dynamically not include them so the error goes away?
The error I get is SQLITE_ERROR: table allPositionsTable has 97
columns but 80 values were supplied and is the one I am trying to
avoid by figuring out a way where this doesn't happen.
This happens because you are using the default column list (i.e. by not specifying the columns into which the values are to be placed)
That is you would be coding the equivalent of INSERT INTO your_table VALUES(.......
so in the absence of a list of columns you are saying that you will provide a value for all columns in the table and hence the message when a value or values are not present.
What you want to do is use INSERT INTO your_table_name (your_comma_separated_list_of_columns_to_be_inserted) VALUES(.......
where your_table_name and your_comma_separated_list_of_columns_to_be_inserted would be replaced with the appropriate values.
See the highlighted section of the INSERT syntax that can be found at SQL As Understood By SQLite - INSERT
and the respective section from the above link is :-
The first form (with the "VALUES" keyword) creates one or more new
rows in an existing table.
If the column-name list after table-name is
omitted then the number of values inserted into each row must be the
same as the number of columns in the table.
In this case the result of
evaluating the left-most expression from each term of the VALUES list
is inserted into the left-most column of each new row, and so forth
for each subsequent expression.
If a column-name list is specified,
then the number of values in each term of the VALUE list must match
the number of specified columns.
Each of the named columns of the new
row is populated with the results of evaluating the corresponding
VALUES expression.
Table columns that do not appear in the column list
are populated with the default column value (specified as part of the
CREATE TABLE statement), or with NULL if no default value is
specified.
I want to copy the content of one column in table A and replace the contents (not insert into it - the number of rows will be the same) of another column in another table.
I can't a where condition, the table has only just been created at this point with one empty timestamp column. it will be populated via pyodbc class after the timestamps have been added - this query will fill the timestamps for me
What is the SQL command for this?
Thanks!
After discussion, this is the query needed : INSERT INTO OCAT_test_table (DateTimeStamp) SELECT DateTimeStamp FROM DunbarGen
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