Jump to content

query with in other query


Guest rajesh2209

Recommended Posts

Guest rajesh2209

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...