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

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

Related

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

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

SQL insert row with one change

I have this table:
Table1:
id text
1 lala
And i want take first row and copy it, but the id 1 change to 2.
Can you help me with this problem?
A SQL table has no concept of "first" row. You can however select a row based on its characteristics. So, the following would work:
insert into Table1(id, text)
select 2, text
from Table1
where id = 1;
As another note, when creating the table, you can have the id column be auto-incremented. The syntax varies from database to database. If id were auto-incremented, then you could just do:
insert into Table1(text)
select text
from Table1
where id = 1;
And you would be confident that the new row would have a unique id.
Kate - Gordon's answer is technically correct. However, I would like to know more about why you want to do this.
If you're intent is to have the field increment with the insertion of each new row, manually setting the id column value isn't a great idea - it becomes very easy for there to be a conflict with two rows attempting to use the same id at the same time.
I would recommend using an IDENTITY field for this (MS SQL Server -- use an AUTO_INCREMENT field in MySQL). You could then do the insert as follows:
INSERT INTO Table1 (text)
SELECT text
FROM Table1
WHERE id = 1
SQL Server would automatically assign a new, unique value to the id field.

How to change the parent value, affect the children value between 2 table in SQL

For example, if there are two tables:
Table 1: Company
which have a attribute : status
Table 2 : Employee
which have a attribute : status
If table 1 attribute change to 1/0, the table 2 have to follow, however, if table 2 change to 1/0, there should be no action for table 1. How to construct that?
You can create database trigger on update of table 1.
If you use MySQL you can read about it here: http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html

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

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