Re: SQL Where LIKE - Range it!
От | Joel Burton |
---|---|
Тема | Re: SQL Where LIKE - Range it! |
Дата | |
Msg-id | Pine.LNX.4.21.0104271034220.17539-100000@olympus.scw.org обсуждение исходный текст |
Ответ на | SQL Where LIKE - Range it! (steagus@S1PA3M2FIL4TE9Ryahoo.com (Steagus)) |
Список | pgsql-general |
On Thu, 26 Apr 2001, Steagus wrote: > > What I'd like to do is pull a list of records where there is a range > of last names; say from A - F. > select * from table where last_name LIKE 'A%' AND last_name LIKE 'F%' > - for example. > > The above code I've tried for this doesn't seem to work as I'd expect > it too? > I've even done > select * from table where last_name LIKE 'A%' AND LIKE 'F%' > > Can anyone provide some details or insights on how to accomplish this? LIKE A% AND LIKE F% means "must start with A *AND* must start with F", so the name "Anderson" would fail because it does start with A, but doesn't start with F. Something like LIKE "A%" OR LIKE "B%" OR LIKE "C%" ... OR LIKE "F%" would do the trick, but slowly, and it's a pain to write out. I'd use BETWEEN 'A' AND 'FZZZ' (or, to be more precise, >='A' and <'G') Keep in mind that PostgreSQL is case-sensitive, so if me name were 'Joel deBurton', you wouldn't find me. If you have lower-case starting names, you'll want to see (BETWEEN 'A' AND 'FZZZ') OR (BETWEEN 'a' AND 'fzzz') HTH, -- Joel Burton <jburton@scw.org> Director of Information Systems, Support Center of Washington
В списке pgsql-general по дате отправления: