Jump to content

Selecting distinct comma-separated values from a column


mishasoni

Recommended Posts

I am somewhat new to php and am in need of some assistance. 

 

I have a mysql table ("Library") with a field called "Tags" that contains a list of comma-separated words that function as tags/categories for a series of publications.  There is a finite number of total tag words, many of which are repeated across records.  I need to select only distinct tags words in order to display a list of available tags/categories. So using

 

SELECT DISTINCT Tags FROM Library WHERE Tags IS NOT NULL

 

 

does not work as this selects distinct field values, not distinct strings within a field. 

 

Can anyone help me out with what the query would look like to select distinct comma-separated words within a field?  I'm desperate!

 

 

 

It would probably be possible, but the complexity of the query, and the performance issues it would have would be terrible.

 

 

 

Why not store tags in rows instead of a CSL?

 

 

Example:

 

CREATE TABLE tag_video (

    video_id int,

    tag varchar(255)

);

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.