Page 1 of 1

How could I reduce this query

Posted: Fri Apr 20, 2007 3:57 am
by impulse()

Code: Select all

SELECT DISTINCT product
FROM scheme.opservm
WHERE product LIKE 'A%'
OR product LIKE 'B%'
OR product LIKE 'C%'
OR product LIKE 'D%'
OR product LIKE 'E%'
Regards,

Posted: Fri Apr 20, 2007 4:03 am
by onion2k
It's less code, and it works, but I'm not sure it's really a good idea:

Code: Select all

SELECT DISTINCT `product` FROM `scheme.opservm` WHERE LEFT(`product`,1) IN ('A','B','C','D','E');
I'd definitely try benchmarking it because it might well be a lot slower.

Posted: Fri Apr 20, 2007 4:15 am
by impulse()
Is there a tool for MySQL benchmarking or is just the case of comparing the "Query took x" time for each query?

Posted: Fri Apr 20, 2007 4:45 am
by impulse()
Also,

Is it possible to use the BETWEEN syntax on letters.

E.G:

Code: Select all

SELECT DISTINCT product
FROM scheme.opservm
WHERE LEFT (product, 1) BETWEEN ('A' AND 'Z')
I realise that query doesn't work but I'm just trying to make my question clearer.

Regards,

Posted: Fri Apr 20, 2007 5:03 am
by onion2k
Yes, you can do that. Remove the brackets after BETWEEN.