tags:

views:

42

answers:

2

i need to get a query where the elements are displayed in case the first letter is E (the word is electronics).. i have tried with the following :

mysql_query("select * from nested_category where name like '[A-F]%'");

Edit : its like i need to choose all the elements for which the first element lie between A & F .. I need all the element such as Elements, Capacitors, Elephant, Accelerators and definitely not Resistors.. I am using this query with PHP...

+2  A: 

WTF has A-F got to do with E?

SELECT * FROM nested_category WHERE name LIKE 'E%'

In response to your edit:

Use the REGEXP function:

SELECT * FROMnested_category WHERE name REGEXP '^[A-E]'

And even still, you now say you want A-E, but your code says A-F? I'm really confused by your question...

Coronatus
for REGEXP '^[A-E]'.... does it refer to the elements that begin with the letters from A to E??? if no, then whts the difference between this way of query and REGEXP '[A-E]'....
Sachindra
[A-E] is reversed in MySQL to [R-Z]. It says that in the documentation page that I linked to and you didn't read.
Coronatus
Sachindra, the "^" character in REGEXP means "start of line" (not negation). If you omit it, the regular expression will match something that merely contains the letter in the bracket group.
JYelton
A: 

The only way to continue using the mySql LIKE syntax is this:

mysql_query("SELECT *
FROM nested_category
WHERE
(name LIKE 'A%'
OR name LIKE 'B%'
OR name LIKE 'C%'
OR name LIKE 'D%'
OR name LIKE 'E%')");
JYelton