if the preview doesnt come out right you can check the text file i post
Hi guys I really need help basically im trying to do a inner join update from table2 to table1. How to do the sql statement for this.
Example
table1
ID Fruit Color ETag Value
1 apple red TAG_TEST 4
2 orange orange TAG_TEST 3
3 cat white TAG_TEST 2
1 apple red TAG_TEST 1
1 apple red TAG_TEST 2
table2
Value Etag
0 BAD
1 Good
2 pretty
3 ok
4 beautiful
table2 has the etag description of the value.
so 0 means bad, 1 means good, 2 means pretty etc.......
Im trying to pull the actual description from table2 and update the etag column where table1.Color -'red'
So basically im searching for the color red and the value red.
Loading
Sam HobbsPosted Mar 10, 2010, 2:46 PM
SET ETag = Table2.Etag
FROM Table1 INNER JOIN
Table2 ON Table1.Value = Table2.Value
WHERE (Table1.Color = 'red')
Sam HobbsPosted Mar 11, 2010, 11:25 PM
David SmithPosted Mar 11, 2010, 11:17 AM
David SmithPosted Mar 10, 2010, 5:51 AM
Im getting a error saying incorrect syntax near 'RIGHT'
so how can i get it to work in c# sql for the table designer command text
David SmithPosted Mar 10, 2010, 5:24 AM
Sam HobbsPosted Mar 9, 2010, 8:58 PM
WHERE (((Table1.Color)="red"));
David SmithPosted Mar 9, 2010, 6:46 PM
for table2 there is no ID coulumn
there is just a value of a string representation and Etag column of a string representation
there is no table 3, the result you have for table 3 is is suppose to be for table 1.
table2 is a defintion table basically.
now basically you search table1 Color field for red and look at the value for the row of red
then go to the defnition table 2 and find out what the value you mean
example
if you look at ID 1 which is the first row, there is a red and the value is 4.
so now you go to table2 to find out what 4 mean. In this case 4 means beautiful.
which comes from table 2, so you take the "beautiful" and update or replace in table 1 under the etag column
you only search where there is a red. do it for the whole table.
so the end result of table 1 should be
table1
row 2 and 3 will not be updated because there is no red.
Sam HobbsPosted Mar 9, 2010, 5:22 PM
Sam HobbsPosted Mar 9, 2010, 5:17 PM
and using the SQL I posted above, the results I get is:
So did I use the wrong input data? Is the output I show above not correct?
Lee SheenePosted Mar 9, 2010, 11:23 AM
SELECT Table1.ID, Table1.Fruit, Table1.Color, Table2.Etag, Table1.Value
FROM Table2
LEFT OUTER JOIN Table1 ON Table2.Value = Table1.Value
WHERE Table1.Color = 'red';
David SmithPosted Mar 9, 2010, 7:48 AM
SELECT Table1.ID, Table1.Fruit, Table1.Color, Table2.Etag, Table1.Value INTO Table3
FROM Table2 RIGHT JOIN Table1 ON Table2.Value = Table1.Value;
David SmithPosted Mar 9, 2010, 3:08 AM
Sam HobbsPosted Mar 9, 2010, 12:41 AM
Amit ChoudharyPosted Mar 9, 2010, 12:00 AM
first do one fetch the value for color red from table 1 using following query:
Now you have to update the table 2 on the basis of values coming from the first query:
so the final sql statement will be look like this:
Hope it solve your problem.
Please mark as answer if it helps you.
David SmithPosted Mar 8, 2010, 6:56 PM
ID Fruit Color ETag Value
1 apple red beautiful 4
2 orange orange TAG_TEST 3
3 cat white TAG_TEST 2
1 apple red Good 1
1 apple red pretty 2