|
Posted by Robert on 12/17/39 11:55
Searching in MySQL can be tricky. If you are wanting to search in MySQL
the correct code examles are true:
(1) Search with wildcards (note "s" in wildcard)
SELECT * FROM table WHERE col LIKE '%search%'
-or-
SELECT DISTINCT * FROM table WHERE col LIKE '%search%'
Notice the % (percent sign), this means it will match "search" with
ANYTHING before -OR- after the search term. But if you only want to
search AFTER the term, you would only use the % sign AFTER. Example:
SELECT * FROM table WHERE col LIKE 'search%'
Same for searching BEFORE the search term. Example:
SELECT * FROM table WHERE col LIKE '%search'
-- This will pull anything that starts with * (wildcard) and includes
"search" after it.
Theres also another way to search by using the wildcard (notice: no
"s") search.
It's somewhat like the first explaination, but different.
SELECT * FROM table WHERE col LIKE 'somthing_'
Notice the _ (underscore) -- This means MySQL will get everything from
the term "something" plus anything after "something" -- for example:
"somethings" will be selected as found in the search. The _ is a
wildcard modifier which will tell MySQL how many wildcards it will
search. For example, if you used 3 underscores ___ it will look for the
search term then anything that has up to 3 wildcards. For example:
SELECT * FROM table WHERE col LIKE 'something___'
You can also use it from a starting point. For example:
SELECT * FROM table WHERE col LIKE '___something'
This is basically the samething as 'something___' but it will get up to
3 wildcards BEFORE the search term.
Helpful? If you're confused you can always visit (MySQL 5+)
http://mysql.com/doc/refman/5.0/en/select.html -or- (MySQL 4+)
http://mysql.com/doc/refman/4.1/en/select.html
Hope this helps, -Rob
jbk@ewebs.gr wrote:
> Hello...
> i have a table which contains a column named "ask" and a column named
> "per"...
> my think is that i want to search in "ask" and echo the data stored in "per"
> for this entry...
> How do i do this?
> Thanx in advance!
> JBK
Navigation:
[Reply to this message]
|