Question

I have this sql query:

SET @row_num=0; 
SELECT @row_num:=@row_num+1 as 'Num', book_title, author_name
FROM books

When I test this query in phpmyadmin, it show result perfectly but when I test it in Pentaho User Console, it show error.

Can anyone tell me what is wrong with my query? Is there any other way I can fix it so that it will show the result perfectly in Pentaho?

No correct solution

OTHER TIPS

Try this code.

SET @row_number:=0;
SELECT @row_number:=@row_number+1 AS row_number,book_title, author_name FROM books;

It might help you.

Try to build a single query, like this:

SELECT
    @row_num := @row_num + 1 as 'Num',
    book_title,
    author_name
FROM
    books JOIN (SELECT @row_num := 0 FROM DUAL) as sub;

The problem currently (I guess), that you have two statements instead of one:

SET @row_num=0;
-- ^ statement #1

SELECT @row_num:=@row_num+1 as 'Num', book_title, author_name
FROM books;
-- ^ statement #2

So try to mix them into one statement, like I mentioned above. For MySQL it is a legal syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top