peted Posted June 14, 2019 Share Posted June 14, 2019 id name status a b c e F 1 Jon open 1 1 2 2 2 Jane open 2 2 2 1 1 3 Billy open 2 2 2 4 Mary closed 2 2 2 5 James Closed 1 2 2 2 6 Jimmy Closed 2 1 Hi, I need some help with some SQL. I need a statement that select a row that have a status of open or if it is closed, one of the columns A-F have a number 1 in it. So in the example table above I would need rows 1, 2, 3 selected as they are open and rows 5 & 6 as they are closed but have a 1 in the A-F columns. Hope this makes sense. Any help would be great. Link to comment Share on other sites More sharing options...
Ingolme Posted June 15, 2019 Share Posted June 15, 2019 This is simple logic. You want to return a row if: Status is open Status is closed and a is 1 or b is 1 or c is 1 or d is 1 or e is 1 or f is 1. This translates to the following WHERE clause: WHERE status = 'open' OR status = 'closed' AND (a = 1 OR b = 1 OR c = 1 OR d = 1 OR e = 1 OR f = 1) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now