RowID no Mysql, mostrando o numero sequencial

Existem algumas formas de retornar o numero sequencial do registro em uma query no mysql.
No Oracle temos o RowId, mas no mysql temos que trazer na unha mesmo. mais ou menos assim:

SET @rowId :=0;
SELECT @rowId := @rowId + 1 , campo from tb_tabela;

Veja a Aplicação em uma Stored Procedure:

DELIMITER $$
CREATE `sp_rowId`()
BEGIN

SET @rowid := 0;
select @rowid:= @rowid+1 as rowid,campo1,campo2 from tb_tabela;

END$$

DELIMITER ;

Advertisement

2 Responses to RowID no Mysql, mostrando o numero sequencial

  1. Rafael Cabral March 27, 2011 at 7:59 pm

    Obrigado.

  2. Eliseu Borges November 7, 2011 at 2:10 pm

    Tenta isso aqui.

    SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE table_name=’nome_da_tabela’;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.