Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

MySQL: SELECT * FROM --- DESC (-1)..

Estas en el tema de MySQL: SELECT * FROM --- DESC (-1).. en el foro de Mysql en Foros del Web. Hola, me gustaría hacer un SELECt en mi base de datos y que me extrajera el penultimo resultado. Se que puedo hacer una variable que ...
  #1 (permalink)  
Antiguo 27/08/2007, 02:07
 
Fecha de Ingreso: agosto-2007
Ubicación: bcn
Mensajes: 6
Antigüedad: 16 años, 8 meses
Puntos: 0
MySQL: SELECT * FROM --- DESC (-1)..

Hola, me gustaría hacer un SELECt en mi base de datos y que me extrajera el penultimo resultado.
Se que puedo hacer una variable que me ordene los resultado y ahi reste uno pero, no se puede hacer directamente en la consulta?
algo asi como desc -1 ..

ni idea..
  #2 (permalink)  
Antiguo 27/08/2007, 02:15
Avatar de pzin
Moderata 😈
 
Fecha de Ingreso: julio-2002
Ubicación: Islas Canarias
Mensajes: 10.488
Antigüedad: 21 años, 8 meses
Puntos: 2114
Re: MySQL: SELECT * FROM --- DESC (-1)..

Prueba con algo como
Código:
select * from tabla order by algo limit 1,2
  #3 (permalink)  
Antiguo 27/08/2007, 03:48
 
Fecha de Ingreso: agosto-2007
Ubicación: bcn
Mensajes: 6
Antigüedad: 16 años, 8 meses
Puntos: 0
Re: MySQL: SELECT * FROM --- DESC (-1)..

graciass!!

la primera parte es l qe especifica desde donde empieza: 0=1=poner el limit de manera simple (por ej, un limit de 4, "limit 4")

funciona, al final tb lo encontre en las instrucciones de mysql:

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements).

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15

To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

With one argument, the value specifies the number of rows to return from the beginning of the result set:

SELECT * FROM tbl LIMIT 5; # Retrieve first 5 rows

In other words, LIMIT row_count is equivalent to LIMIT 0, row_count.

For prepared statements, you can use placeholders (supported as of MySQL version 5.0.7). The following statements will return one row from the tbl table:

SET @a=1;
PREPARE STMT FROM 'SELECT * FROM tbl LIMIT ?';
EXECUTE STMT USING @a;

The following statements will return the second to sixth row from the tbl table:

SET @skip=1; SET @numrows=5;
PREPARE STMT FROM 'SELECT * FROM tbl LIMIT ?, ?';
EXECUTE STMT USING @skip, @numrows;

For compatibility with PostgreSQL, MySQL also supports the LIMIT row_count OFFSET offset syntax.

If LIMIT occurs within a subquery and also is applied in the outer query, the outermost LIMIT takes precedence. For example, the following statement produces two rows, not one:

(SELECT ... LIMIT 1) LIMIT 2;
  #4 (permalink)  
Antiguo 27/08/2007, 10:06
Avatar de BrujoNic
Super Moderador
 
Fecha de Ingreso: noviembre-2001
Ubicación: Costa Rica/Nicaragua
Mensajes: 16.935
Antigüedad: 22 años, 5 meses
Puntos: 655
Re: MySQL: SELECT * FROM --- DESC (-1)..

Hay un sección solo de MySQL, muevo tu mensaje a esa sección y trata de colocar tus consultas en las secciones correspondiente.

Saludos.
__________________
La tecnología está para ayudarnos. No comprendo el porqué con esa ayuda, la gente escribe TAN MAL.
NO PERDAMOS NUESTRO LINDO IDIOMA ESPAÑOL
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:14.