Jump to content

[SOLVED] [5.0.51a] NOT BETWEEN issue.. Please help


Speedy84

Recommended Posts

I've been trying to figure out why this doesn't work properly, but with no luck :(

 

Issue:

It sorts out everything from A to Y, but returns all entries starting with a Z.

 

mysql_query("SELECT * FROM `artists` WHERE `name` NOT BETWEEN 'a%' AND 'z%' ORDER BY `name` ASC")

 

Thanks in advance

/Speedy

The % wildcard only has meaning in a LIKE statement.

 

The way you are using it means everything greater or equal to the string "a%" and everything leas than or equal the string "z%". Well "za...", "zb..."... are all greater than the string "z%", which is why they show up in the result set.

That is because "z-anything" is greater than "z-null"

 

It appears you want to select names that begin with anything other than a letter? This should work (untested) -

 

mysql_query("SELECT * FROM `artists` WHERE LOWER(LEFT(`name`, 1)) NOT BETWEEN 'a' AND 'z' ORDER BY `name` ASC")

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.