SQL Queries....
cbbrowne-HInyCGIudOg at public.gmane.org
cbbrowne-HInyCGIudOg at public.gmane.org
Fri Oct 3 03:04:04 UTC 2003
> I've been working with some SQL driven sights. Mostly Postgres and some
> MySQL, However I've never had to do this before:
>
> Does anyone know how to select only records that start with a certain
> letter?
>
> I can easly select records that contain the letter and order them
> properly, but that dosn't help much. :(
In standard SQL, the "wildcards" are a little different from what you
are accustomed to:
- The equivalent to "*" is "%"
- The equivalent to "?" is "_"
- You use single quotes to enclose strings, so use 'something'
rather than "something".
PostgreSQL also supports, using the ~ operator, pretty full-scale
regular expressions.
So, you might have a query to look for people with names starting with
"B":
select * from some_table where name like 'B%';
If you need case insensitivity, you might use:
select * from some_table where lower(name) like 'b%';
To search for a field 3 characters long, you might try:
select * from another_table where some_column like '___';
--
"cbbrowne","@","ntlug.org"
http://cbbrowne.com/info/finances.html
"As soon as we started programming, we found to our surprise that it
wasn't as easy to get programs right as we had thought. Debugging had
to be discovered. I can remember the exact instant when I realized
that a large part of my life from then on was going to be spent in
finding mistakes in my own programs."
-- Maurice Wilkes discovers debugging, 1949
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list