SQL WHERE returns unwanted values

1
SELECT x, y, z, f , g , h 
FROM torrents
INNER JOIN w ON w = x
WHERE y =  '2' OR y =  '7'
AND  f =  '1'
AND h < 4294967296

I set the f = '1' in where so that it returns only the values with f = 1 so it returns values with 0 and also returns me values with the largest Size.

Ex:

    
asked by anonymous 18.02.2018 / 03:25

1 answer

4

If OR is only in Y, it needs parentheses, otherwise any y = 2 returns, regardless of the values of f and h .

Otherwise, you have to see if JOIN is correct, it would be best not to use equal names in fields and tables.

Possible solution (correct tabela1.w for the right field name):

SELECT x, y, z, f , g , h 
FROM torrents AS tabela1
INNER JOIN w  AS tabela2
           ON tabela1.w = tabela2.x
WHERE ( y =  '2' OR y =  '7' )
AND  f =  '1'
AND h < 4294967296

If you want to make it a bit more elegant, you can use IN and take the quotes:

SELECT x, y, z, f , g , h 
FROM torrents
INNER JOIN w ON w = x
WHERE y IN ( 2, 7 )
      AND f = 1
      AND h < 4294967296
    
18.02.2018 / 03:40