Re: [GENERAL] SQL Where LIKE - Range it!

2001-04-27 Thread Frank Bax

select * from table where last_name ~ '^[A-F]';
or
select * from table where last_name between 'A' and 'G';
or
select * from table where last_name ='A' and last_name'G'

The second one is broken if last_name='G' returns something.
Use ~* in first example to ignore case.

Frank

At 08:16 PM 4/26/01 GMT, you wrote:
H-

I've found the docs on how to select a list of rows from a table were
all the records have a last name starting with 'W%'. 
select * from table where last_name LIKE 'W%'

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?


Thanks. Much appreciated.
-Steagus


---(end of broadcast)---
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster



Re: [GENERAL] SQL Where Like - Range it?!

2001-04-27 Thread Len Morgan

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?

SELECT * FROM table WHERE last_name BETWEEN 'A' AND 'Fz' ;
worked for me.

You could also use BETWEEN 'A' AND 'G' to avoid all of the s at the
end.  Crude but effective.

len morgan


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly