WHERE do SQL returns unwanted values

Asked

Viewed 43 times

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 named the f = '1' in the where so that he returns to me only the values with f = 1 only it returns values with 0 and also returns values with the larger size.

Ex:

screenshot parcial

  • Columns Y and F are INT or VARCHAR? Put the table structure there.

  • 1

    Already managed to solve , thanks for trying to help!

1 answer

3


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

Other than that, you have to see if JOIN is correct, it would be better not to use equal names in fields and tables.

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

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 little more elegant, you can use IN and remove the quotation marks:

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
  • Thank you , I’m learning SQL yet and put me to move this in the company was hitting head .

  • The structures think better not because it is the company system , I do not want to give roll to min.

  • @Arthuraires was just using the DESCRIBE nome_da_tabela, copy and paste, no data display.

  • Okay, when I get home I do, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.