0

Trying to create a tag cloud with tips from https://www.quora.com/What-is-the-easiest-way-to-create-a-tag-cloud-from-a-MySQL-column

I'm creating a new table within a database. Database has table named 'tracks' Table has column called 'tag' 'Tag' fields are populated with tags separated by commas ie tag01,tag02,tag03, etc

I am trying to create a new table which

I have run the following

CREATE TABLE counter (
    id int unsigned NOT NULL AUTO_INCREMENT,
    primary key (id)
);
----
delimiter //
CREATE PROCEDURE populate_counter()
BEGIN
    SET @i = 0;
    SET @n = (select max(LENGTH(tag) - LENGTH(REPLACE(tag, ' ', ''))+1) from tracks);
    WHILE @i<@n DO
        INSERT INTO counter (id) VALUES (NULL);
        SET @i = @i + 1;
    END WHILE;
END
//
delimiter ;
----

That part seems to have gone OK. I then try and run the procedure

call populate_counter()
----
select 
    word, 
    count(*) as freq
from (
    select 
        case 
            when id <= LENGTH(tag) - LENGTH(REPLACE(tag, ' ', ''))+1 then SUBSTRING_INDEX(SUBSTRING_INDEX(tag, ' ', id), ' ', -1) 
            else '' 
        end as word 
    from tracks, counter
) t
where 
    0 < LENGTH(word)
group by word

I get this:

MySQL #1052 - Column 'id' in field list is ambiguous.

Not sure how to proceed from there.

Any advice most welcome!

Apache/2.4.10 (Debian) Database client version: libmysql - 5.5.57 PHP extension: mysqli

Thanks

eezzee
  • 89
  • 1
  • 9
  • Possible duplicate of [1052: Column 'id' in field list is ambiguous](https://stackoverflow.com/questions/6638520/1052-column-id-in-field-list-is-ambiguous) – Willem Renzema Oct 14 '17 at 16:24
  • Thanks for the link, but it seems that the case example deals with 2 'id' fields present. I just have one created. And now i seem to have another message instead: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select word, count(*) as freq from ( select case when id <= LE' at line 2 – eezzee Oct 15 '17 at 23:17

0 Answers0