Gigante
Gigante

Reputation: 327

MySQL - need to select negative values as positive

I have 2 MySQL tables: subscriptions and groups. Column sid in table subscriptions contains negative values but column id in table groups contain the same values but positive.

I need some method to convert sid values to positive values before joining table groups, or a query that will treat all values in table id as negative values

Below is my query. It doesn't return any results because column sid contains negative values, but column id contains positive values

$tmp = mysqli_query($con1,"
SELECT s.uid 
     , s.sid
     , g.title 
  FROM subscriptions s 
  LEFT
  JOIN groups g 
    ON s.sid = g.id  
 WHERE s.uid = $id 
 LIMIT 0,20
") or die('Error8');

Upvotes: 4

Views: 8259

Answers (1)

Jim
Jim

Reputation: 22646

The ABS function will do what you need:

Returns the absolute value of X.

See https://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_abs

Upvotes: 6

Related Questions