Search code examples
mysqlsqlsqlyog

Negating an integer which sql query returned


I have a SQL sub query,

SELECT `generateoffset` FROM `opa`.`sddrecurrencetype` WHERE `sddrecurrencetypeid`=1;

it returns as a result 6

What I am wondering is that, if its possible to get negative of what the value is returned from the query.

I tried to do it like this,

-(SELECT `generateoffset` FROM `opa`.`sddrecurrencetype` WHERE `sddrecurrencetypeid`=1)

I thought may be it will give me negative of what the result of the query would be like -6, but alas its not working like this.

Can some one please tell me , if its possible what I am trying to do.

Thanks in Advance!!!


Solution

  • Just multiply the column result rather than the entire query:

    SELECT `generateoffset` * -1 as 'generateoffset' 
    FROM `opa`.`sddrecurrencetype` 
    WHERE `sddrecurrencetypeid`=1;