Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
James M.
Forum Contributor
Posts: 119 Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee
Post
by James M. » Thu May 20, 2004 4:59 pm
Hi, i am trying to extract data from a MySQL database where i only extract the data from a row that begins with a certain letter of the alphabet, like in table 'users' row 'user' i am trying to select all the users who have names beginning with the letter 'A'. Does anyone know a way?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu May 20, 2004 5:01 pm
SELECT u.user FROM users u WHERE u.user LIKE 'a%'
I think...
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Thu May 20, 2004 5:01 pm
read on the LIKE command
combine that with the wildcard % and you have a search function for MySQL
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Thu May 20, 2004 5:02 pm
James M.
Forum Contributor
Posts: 119 Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee
Post
by James M. » Thu May 20, 2004 5:13 pm
feyd wrote: SELECT u.user FROM users u WHERE u.user LIKE 'a%'
I think...
Yup thats it, thanks.
But one more thing, how would u filter it so that only numbers/special characters are selected?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu May 20, 2004 5:22 pm
regex!
http://dev.mysql.com/doc/mysql/en/Regexp.html
SELECT u.user FROM users u WHERE u.user REGEXP '^a[^[:alnum:]]'
might need to be:
SELECT u.user FROM users u WHERE u.user = REGEXP '^a[^[:alnum:]]'
I, uh, think..
James M.
Forum Contributor
Posts: 119 Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee
Post
by James M. » Thu May 20, 2004 5:28 pm
Thanks, i didn't know regular expressions could be used in MySQL, i've gotta read that manual....thanks for the help once again.
James M.
Forum Contributor
Posts: 119 Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee
Post
by James M. » Thu May 20, 2004 7:26 pm
im having trouble with REGEXP, im tryin to search for any users that do not begin with an alpha character.
i tried this but its not working:
SELECT u.user FROM users u WHERE u.user = REGEXP '^[^[:alpha:]]'
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu May 20, 2004 8:02 pm
tried running that in phpmyadmin?
I just checked in mine..
try:
SELECT u.user FROM users u WHERE u.user REGEXP '^[^[:alpha:]]'
that worked for me.
James M.
Forum Contributor
Posts: 119 Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee
Post
by James M. » Thu May 20, 2004 8:43 pm
I got it to work in my script now. I had to find something to initiate the query. Thanks a lot for the help.