Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:58:15+00:00 2026-06-11T01:58:15+00:00

This is my first time dealing with cursors and procedures in MySQL. I have

  • 0

This is my first time dealing with cursors and procedures in MySQL. I have followed the examples given in MySQL documentation on cursors and roseindia.net and now encounter an error:

Column count doesn’t match value count at row 1

Here are the tables involved (the tables are not normalised to 3NF yet as I receive them as so, and yes, I do realised that I would need to use artists.id instead of artists.name):

CREATE TABLE `user_artists_rankings` (
  `user_id` varchar(50) NOT NULL DEFAULT '' COMMENT 'kpop_users.user_id',
  `artist_name` varchar(100) NOT NULL,
  `calculated_score` int(11) DEFAULT NULL,
  `last_calculated_score_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`user_id`,`artist_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `kpop_users` (
  `user_id` char(50) NOT NULL,
  `username` char(150) DEFAULT '',
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`user_id`) USING BTREE,
  KEY `name_idx` (`username`),
  KEY `twitter_id_idx` (`twitter_user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
CREATE TABLE `artists` (
  `name` varchar(100) NOT NULL,
  `type` varchar(45) DEFAULT NULL,
  `official_twitter_screenname` varchar(45) DEFAULT NULL,
  `thumbnail_url` varchar(500) DEFAULT NULL,
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
  KEY `Index_2` (`official_twitter_screenname`)
) ENGINE=InnoDB AUTO_INCREMENT=164 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

The objective is to have user-artist(n) rows in the table, user_artists_rankings, i.e:

user1 | artist1
user1 | artist2
user1 | artist3
user2 | artist1
user2 | artist2
user2 | artist3

Here is the procedure I have created:

delimiter ;
drop procedure if exists testrun;
delimiter //
create procedure testrun()
begin
    declare d int default 0;
    declare user_id varchar(50);
    declare artist_name varchar(100);
    declare cur_users cursor for select user_id from kpop_users;
    declare cur_artists cursor for select name from artists;
    declare continue handler for sqlstate '02000' set d=1;
    declare continue handler for sqlstate '23000' set d=1;
    open cur_users;
    open cur_artists;
    lbl1: loop 
        if d=1 then 
            leave lbl1;
        end if;
        if not d=1 then
            fetch cur_users into user_id;
            lbl2: loop
                if d=1 then
                    leave lbl2;
                end if;
                if not d=1 then
                    fetch cur_artists into artist_name;
                    insert into user_artists_rankings values (user_id, artist_name);
                end if;
            end loop lbl2;
        end if;
    end loop lbl1;
    close cur_users;
    close cur_artists;
end
//
delimiter ;
call testrun();

Any help would be greatly appreciated.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:58:17+00:00Added an answer on June 11, 2026 at 1:58 am

    This line of code is wrong:

    insert into user_artists_rankings values (user_id, artist_name);
    

    Since the table has 4 fields and you are using only two of them for INSERT, you need to specify which ones are used. It should be:

    insert into user_artists_rankings(`user_id`, `artist_name`) VALUES(user_id, artist_name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First time with this trouble when dealing with a MySQL table. I'm inserting bar
This was the first time I encountered this kind of error after dealing with
Hi, ive been dealing with this for some time now and need your help.
Sorry for the kind of n00b question, but this is my first time dealing
My first time dealing with this technology. Essentially I got a core data database
First time dealing with json. I have a php file that processes the post
This is my first time dealing with windows. I tried to create thread, but
I'm now dealing with PLSQL developer, which is my very first time. And I
This is my first time working with a WPF datagrid. From what I understand
this is my first time asking a question here. I tried to be well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.