0

When running the following query:

SELECT id,name,verified FROM servers WHERE verified=1 AND enabled=1 AND suspended=0 AND name LIKE '%.net%' || ip LIKE '%.net%' ORDER BY score DESC

MySQL is returning incorrect results. Here is the result of that input:

+----+-------------------+----------+
| ID |       name        | verified |
+----+-------------------+----------+
| 34 | BlockedUp         |        1 |
|  8 | aliacraft         |        1 |
| 27 | Limitless MC      |        1 |
| 31 | OPCraft           |        1 |
| 33 | LoneWolves Prison |        1 |
| 47 | purpleprison.net  |        0 |
+----+-------------------+----------+

What could be the reason for this? The last row does obviously not match the requirement of verified=1.

3
  • 1
    You need to group the conditions in the Where condition Commented Apr 17, 2015 at 19:09
  • 1
    @james The OR '%.net%' is independent of the other conditions unless you have them wrapped in ()'s you're query says (enabled=1 and suspended = 0 and name like.net) or (ip like '%.net%') What's the IP of ID 47? I'm guessing it has .net in it. Commented Apr 17, 2015 at 19:10
  • Thanks everyone, I've solved the problem now with Abhik's answer. Commented Apr 17, 2015 at 20:21

1 Answer 1

4

You need to move

AND name LIKE '%.net%' || ip LIKE '%.net%'

in braces as

AND ( name LIKE '%.net%' or ip LIKE '%.net%' )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.