Jump to content

Distinct Substring Query


skeezmo

Recommended Posts

Hello,

I have a large list of songs and artists and I am creating a playlist.  At the top, I have the user select a letter which will then direct them to artists that start with that letter.

The problem I am running into is for artists that start with a number should be going under a separate category [b]0-9 and '[/b].  But instead they are going as individual numbers in the list.

The query I am running for this is:  [code]SELECT distinct substr(artist, 1,1) as browse FROM songlist WHERE songtype = "S" or songtype = "C" ORDER by artist asc[/code]

I have tried adding into the where clause AND songlist.browse not like '1%') etc.

My question is, can I run a query and exclude numbers from returning in the result?

Does anyone have any suggestions that I could use to accomplish this?

Thank you in advance to anyone who may be of help.

Hess Smith
Link to comment
Share on other sites

You should probably be able to use a regex and exlude the appropriate character class (UNTESTED):

[code]SELECT distinct substr(artist, 1,1) as browse FROM songlist WHERE songtype = "S" or songtype = "C" AND LEFT(artist,1) REGEXP "^[0-9']" ORDER by artist asc[/code]
Link to comment
Share on other sites

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.