Can i use LIKE twice?
i want to make a mysql selection but i need to select two types of data, on开发者_StackOverflow中文版e starting with 0256 and other with 0356. can i use:
SELECT * FROM table WHERE tel LIKE '0256%' AND '0356%'
?
thanks, Sebastian
EDIT
i have a problem with these queries in PHP.
the query above, works fine in mysql, but in PHP i get results only for LIKE '0256%'
You are probably looking for a query like this:
SELECT * /* Select all columns */
FROM table /* from the table named 'table' */
WHERE tel LIKE '0256%' /* where the field 'tel' starts with '0256' */
OR tel LIKE '0356%' /* or where the field 'tel' start with '0356' */
You had 2 problems using AND instead of OR, and not having LIKE before the second parameter
SELECT * FROM table WHERE tel LIKE '0256%' OR tel LIKE '0356%'
You can also use a REGEX for this:
SELECT *
FROM table
WHERE tel RLIKE '0[23]56.*'
This may make things clearer as more digit options get added (assuming they will). It might also make the query faster, but profiling would have to be performed to see if this is in fact the case.
精彩评论