Guest rajesh2209 Posted February 23, 2006 Share Posted February 23, 2006 hi i want to write a query with in some other query can any body guide me to that EX: update table_name set col_3='(select sum(col_2) from table_name groupby col_1)' where col_1=col_1this query is generating an error saying that synstax error(Syntax error (missing operator) in query expression 'City='(select City from customers where CompanyName='Alfreds Futterkiste')'') , how can i rectify that error . Link to comment Share on other sites More sharing options...
sbrownii Posted February 23, 2006 Share Posted February 23, 2006 The original SQL would be helpful...In one of the statements you provide you are summing columns (BTW it should be "group by" not "groupby" , in another setting the city for a customer....Also if you in your update statement, you aren't actually allowed to SELECT from the same table you are updating.Also, '(select sum(col_2) from table_name groupby col_1)' will not return what you are expecting... remove those single quotes!Won't col_1 always be equal to itself?As for your syntax error, please show us the statement you are using!!Again, you should remove the single quotes, or you will not get the value you expect!If you are having problems we need to see the actual SQL statements you are using. Link to comment Share on other sites More sharing options...
trial Posted February 24, 2006 Share Posted February 24, 2006 I want to tell you most of the time whenever u used any statements with in quotes it is always considered as string.......EX:::wrong way->SET col1= 'select Sum(col2) from table'right way-->SET col1= select Sum(col2) from tablein first case col1 will consider (select Sum(col2) from table) as string not a query which will give it the sum of the col2 column.so second one is the right way. Link to comment Share on other sites More sharing options...
syedhameed Posted March 2, 2006 Share Posted March 2, 2006 Hi, You can try this it may help u out...update table_name set col_3= (select sum(col_2) from table_name as a where a.col_1 = table_name.col1) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now