syntax problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

syntax problem

Post 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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Code: Select all

SELECT * FROM `members` WHERE 'username' contains '%text%';
searches for that string
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

Post 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]
tonic889
Forum Newbie
Posts: 8
Joined: Fri Apr 16, 2004 9:07 pm

Post 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.
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post 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.
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

Post by glennn3 »

yes, thanks to all...
Post Reply