Is there anyway to compare a field with multiple string values using
LIKE?
Here's the statement I have now:
SELECT * FROM list
WHERE email LIKE CONVERT( _utf8 'h******@hotmail.com' USING latin1 )
OR email LIKE CONVERT( _utf8 'j***@hotmail.com' USING latin1 )";
I know how to do it using the IN operator,
SELECT * FROM list
WHERE email IN ('h******@hotmail.com', 'j***@hotmail.com')
but I need to be able to use the LIKE operator with the CONVERT
function. The reason I am asking is because I am trying to match 50+
different email addresses.
Anyway how to do this?
TIA 4 19781
Evil Bert wrote: Is there anyway to compare a field with multiple string values using LIKE?
Here's the statement I have now: SELECT * FROM list WHERE email LIKE CONVERT( _utf8 'h******@hotmail.com' USING latin1 ) OR email LIKE CONVERT( _utf8 'j***@hotmail.com' USING latin1 )";
I know how to do it using the IN operator, SELECT * FROM list WHERE email IN ('h******@hotmail.com', 'j***@hotmail.com')
but I need to be able to use the LIKE operator with the CONVERT function. The reason I am asking is because I am trying to match 50+ different email addresses.
Anyway how to do this?
I don't understand why you need to use LIKE, since you aren't using any
wildcards in your examples above. So the usage of LIKE is simply
testing for string equality. You could replace the instances of LIKE
with the = sign and it work the same, as far as I know.
Anyway, no, the IN operator does strict equality comparisons, it has no
support for wildcards.
However, if you did need to do comparisons with wildcards against many
patterns, I would suggest loading the patterns into a temporary table,
joining your `list` table to that temp table, and then using LIKE in the
join condition.
Regards,
Bill K.
Doesn't the LIKE compare the string regardless of upper or lower case.
When using = the exact case is searched for. Correct me if I am wrong.
Thanks
On Thu, 20 Oct 2005 19:18:40 -0700, Bill Karwin <bi**@karwin.com>
wrote: Evil Bert wrote: Is there anyway to compare a field with multiple string values using LIKE?
Here's the statement I have now: SELECT * FROM list WHERE email LIKE CONVERT( _utf8 'h******@hotmail.com' USING latin1 ) OR email LIKE CONVERT( _utf8 'j***@hotmail.com' USING latin1 )";
I know how to do it using the IN operator, SELECT * FROM list WHERE email IN ('h******@hotmail.com', 'j***@hotmail.com')
but I need to be able to use the LIKE operator with the CONVERT function. The reason I am asking is because I am trying to match 50+ different email addresses.
Anyway how to do this?
I don't understand why you need to use LIKE, since you aren't using any wildcards in your examples above. So the usage of LIKE is simply testing for string equality. You could replace the instances of LIKE with the = sign and it work the same, as far as I know.
Anyway, no, the IN operator does strict equality comparisons, it has no support for wildcards.
However, if you did need to do comparisons with wildcards against many patterns, I would suggest loading the patterns into a temporary table, joining your `list` table to that temp table, and then using LIKE in the join condition.
Regards, Bill K.
Evil Bert wrote: Doesn't the LIKE compare the string regardless of upper or lower case. When using = the exact case is searched for. Correct me if I am wrong.
All string comparisons in MySQL are case-insensitive, unless by use of
the BINARY keyword they are made to be case-sensitive.
Try executing the following expressions:
SELECT 'abc' LIKE 'abc';
SELECT 'abc' LIKE 'ABC';
SELECT 'abc' LIKE BINARY 'abc';
SELECT 'abc' LIKE BINARY 'ABC';
SELECT 'abc' = 'abc';
SELECT 'abc' = 'ABC';
SELECT 'abc' = BINARY 'abc';
SELECT 'abc' = BINARY 'ABC';
SELECT 'abc' IN ('abc');
SELECT 'abc' IN ('ABC');
SELECT 'abc' IN (BINARY 'abc');
SELECT 'abc' IN (BINARY 'ABC');
See http://dev.mysql.com/doc/refman/5.0/...functions.html
for a reference.
Regards,
Bill K.
Thanks Bill, I just learned something new. I just thought the = equal
sign did an exact match. I guess it's from using PHP so much that I
thought this way...
Thanks again.
On Thu, 20 Oct 2005 21:28:54 -0700, Bill Karwin <bi**@karwin.com>
wrote: Evil Bert wrote: Doesn't the LIKE compare the string regardless of upper or lower case. When using = the exact case is searched for. Correct me if I am wrong.
All string comparisons in MySQL are case-insensitive, unless by use of the BINARY keyword they are made to be case-sensitive.
Try executing the following expressions:
SELECT 'abc' LIKE 'abc'; SELECT 'abc' LIKE 'ABC'; SELECT 'abc' LIKE BINARY 'abc'; SELECT 'abc' LIKE BINARY 'ABC'; SELECT 'abc' = 'abc'; SELECT 'abc' = 'ABC'; SELECT 'abc' = BINARY 'abc'; SELECT 'abc' = BINARY 'ABC'; SELECT 'abc' IN ('abc'); SELECT 'abc' IN ('ABC'); SELECT 'abc' IN (BINARY 'abc'); SELECT 'abc' IN (BINARY 'ABC');
See http://dev.mysql.com/doc/refman/5.0/...functions.html for a reference.
Regards, Bill K. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matthew Louden |
last post by:
I want to know why C# doesnt support multiple inheritance? But why we can
inherit multiple interfaces instead? I know this is the rule, but I dont
understand why. Can anyone give me some concrete...
|
by: Peter Kirk |
last post by:
Hi
I am looking at some code which in many places performs string comparison
using == instead of Equals.
Am I right in assuming that this will in fact work "as expected" when it is
strings...
|
by: spam.noam |
last post by:
Hello,
Guido has decided, in python-dev, that in Py3K the id-based order
comparisons will be dropped. This means that, for example, "{} < "
will raise a TypeError instead of the current...
|
by: nitro_punk85 |
last post by:
I'm working on a project for my c++ class and I am having trouble
comparing one string to two others using the or operator. It looks
something like this:
if(answer3 == answer1 || answer2)
Is...
|
by: eastern_strider |
last post by:
I'm running into problems about defining a comparison function for a
map which has a user defined key. For example:
class Key {
public:
string name;
int number;
Key (na, nu) : name (na),...
| |
by: Gerard Kramer |
last post by:
Hello,
There is a slight problem with operator overloading in a program I
attempt to start practising C++. It is a basic (not very original) game
of life simulator. It uses two classes:...
|
by: Daz |
last post by:
Hello people!
(This post is best viewed using a monospace font).
I need to create a class, which holds 4 elements:
std::string ItemName
int Calories
int Weight
int Density
|
by: jorgedelgadolopez |
last post by:
Hi all,
I am using the xpathnavigator evaluate function on .net (xpath 1
right?). Now I need to expand the code to do multiple contains,
compare dates (such as 'before', 'between' and 'after'),...
|
by: Andrus |
last post by:
I created dynamic extension methods for <= and < SQL comparison operators:
public static IQueryable<TLessThanOrEqual<T>(this IQueryable<Tsource,
string property, object value);
public static...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |