Jump to content

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


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")

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.