2

I'm trying to run a query that selects an id that's between two strings. the query I'm using is

select netid from ALL_GROUP_MEMBERS_VIEW where netid >'aa%' and netid < 'b%' and
      gid='213' order by netid

This obviously isn't working, but I'm not sure how to get those values. Netid is a unique identifier for an individual.

3
  • 1
    Could you post some sample data and the result you're trying to get? Commented Jul 17, 2014 at 16:22
  • Put sample data in text, and the result you wish to achieve so that the others may better help you. Commented Jul 17, 2014 at 16:27
  • Sorry, that was a typo. I meant to post "Can't post data because the table contains sensitive information". Mureinik's answer below fixed my issue. Once I took the wildcard out, it worked. Commented Jul 17, 2014 at 18:28

2 Answers 2

1

The % character is a wildcard for the LIKE operator, and has no function (other than as a literal) in string comparison operations. If you remove it, you should get the right behavior:

SELECT   netid
FROM     all_group_members_view
WHERE    netid > 'aa' AND netid < 'b' AND gid = '213'
ORDER BY netid

To make this query more elegant, you can replace the pair of > and < operators with a single between operator:

SELECT   netid
FROM     all_group_members_view
WHERE    netid BETWEEN 'aa' AND 'b' AND gid = '213'
ORDER BY netid
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Taking the wildcard out fixed it.
0

You can try this:

select netid 
    from ALL_GROUP_MEMBERS_VIEW 
    where substr(netid,1,1) between 'A' and 'B' 
        and gid='213' 
    order by netid

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.