Question:
Syntax SQL (WHERE,AND,LIKE)?
anonymous
2012-07-18 21:37:47 UTC
What is wrong with this syntax? I not only take account of LOL

"select * from registered_members where username = '$username' AND LIKE '%LOL%' "
Four answers:
TheMadProfessor
2012-07-19 06:32:57 UTC
You need a column name between AND and LIKE. Even if username was the one you wanted to use, you need to explicitly specify it for each part of the WHERE.
jnbill1204
2012-07-19 04:51:55 UTC
The issue is that you where statement is ambiguous. When you use the AND keyword you need to specify what you want to target.



So your query should look like this:



"SELECT * FROM `registered_members` WHERE `username` = '$username' AND `username` LIKE '%LOL%' "
anonymous
2012-07-19 04:40:06 UTC
LIKE is another keyword that is used in the WHERE clause. Basically, LIKE allows you to do a search based on a pattern rather than specifying exactly what is desired (as in IN) or spell out a range (as in BETWEEN). The syntax is as follows:



SELECT "column_name"

FROM "table_name"

WHERE "column_name" LIKE {PATTERN}



{PATTERN} often consists of wildcards. We saw several examples of wildcard matching in the previous section. Below we use an example to see how wildcard is used in conjunction with LIKE:
the_justin
2012-07-19 05:14:10 UTC
maybe what you want is:

select * from registered_members where username = '$username' OR username like '%LOL%'


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...