1

I am trying to figure out what SQL query I need to fetch records from my users table.

"SELECT * FROM users WHERE level!='4'"

Level 4 users are "COMPLETED" so by default, they are not shown. But I do want to show users that are COMPLETED if their ACTIVITY value is less than 5. Any user with an activity value of 5 is "Green" and does not require my attention.

Knowing my luck, it's a very simple answer, but it's been a long day and my head is fried.

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
Craigy Craigo
  • 218
  • 2
  • 11

3 Answers3

3

You can do like so:

SELECT * 
FROM users 
WHERE level <> '4'
OR (level = '4' and Activity < 5);

I've switched the inequality operator - <> is more portable

Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285
2

This should solve your problem

SELECT * FROM users WHERE level != '4' OR (activity < '5' AND level = '4' )

cerberus
  • 531
  • 4
  • 14
0

simple method like following as:

SELECT * FROM users
LIMIT 4;
jmail
  • 5,944
  • 3
  • 21
  • 35