Page 1 of 1

syntax problem

Posted: Sat Apr 17, 2004 2:22 pm
by glennn3
can't find the right syntax for this concept in the manual...

i need to do this:

SELECT * FROM `members` WHERE 'username' contains ' ';

// i need to find all the records where people have used a space in their usernames...

is "contains" right, or is the space the problem...?

thanks

glenn

Posted: Sat Apr 17, 2004 2:31 pm
by malcolmboston

Code: Select all

SELECT * FROM `members` WHERE 'username' contains '%text%';
searches for that string

Posted: Sat Apr 17, 2004 3:13 pm
by glennn3

Code: Select all

Error

SQL-query :  

SELECT * 
FROM `members` 
WHERE 'username'contains % m % 
LIMIT 0 , 30 

MySQL said: 


#1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'contains '%me%' LIMIT 0, 30' at line 3
[/b]

Posted: Sat Apr 17, 2004 3:32 pm
by tonic889
Not sure about CONTAINS, but using LIKE does the trick for me:

Code: Select all

select * from members where username LIKE '% %';
The latest version of MySQL also supports a REGEXP keyword that you can use for more advanced expressions.

Posted: Sat Apr 17, 2004 3:33 pm
by yosuke_
You can try:

Code: Select all

SELECT username FROM members WHERE username like ' ';
or:

Code: Select all

SELECT username FROM members WHERE username like '% %';
% - Stands for Wildcard. For exaple if you type:

Code: Select all

SELECT username FROM members WHERE username like '%uke';
and row looks like this:

someone
something
yosuke

it will display: yosuke, becuase it will search for username who ends with uke.

Posted: Sat Apr 17, 2004 4:31 pm
by glennn3
yes, thanks to all...