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

Problemas con ORDER BY y GROUP BY

Estas en el tema de Problemas con ORDER BY y GROUP BY en el foro de Mysql en Foros del Web. Tengo esta consulta Código: SELECT h.idhabitacion, h.descripcionh, h.habit_x_hotel, ho.descripcionho FROM habitacion h INNER JOIN hotel ho ON h.habit_x_hotel = ho.idhotel where h.habit_x_hotel = '1' GROUP ...
  #1 (permalink)  
Antiguo 11/03/2013, 14:37
 
Fecha de Ingreso: noviembre-2012
Ubicación: Villa Maria, Peru
Mensajes: 46
Antigüedad: 11 años, 5 meses
Puntos: 0
Problemas con ORDER BY y GROUP BY

Tengo esta consulta
Código:
SELECT
h.idhabitacion,
h.descripcionh,
h.habit_x_hotel,
ho.descripcionho
FROM habitacion h
INNER JOIN hotel ho ON h.habit_x_hotel = ho.idhotel
where h.habit_x_hotel = '1'
GROUP BY h.idhabitacion
ORDER BY h.habitacionh DESC
pero no me ordena por la habitacion, me lo deja como estaba,
lo curioso es que si "hace caso" cuando quito el group by:

Código:
SELECT
h.idhabitacion,
h.descripcionh,
h.habit_x_hotel,
ho.descripcionho
FROM habitacion h
INNER JOIN hotel ho ON h.habit_x_hotel = ho.idhotel
where h.habit_x_hotel = '1'
ORDER BY h.habitacionh DESC
ahi si me funciona, ¿a que se debe?
  #2 (permalink)  
Antiguo 11/03/2013, 14:43
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 5 meses
Puntos: 2658
Respuesta: Problemas con ORDER BY y GROUP BY

Agrupa por el primero que encuentra. el resto se solapa:
Código MySQL:
Ver original
  1.   (SELECT
  2.       h.idhabitacion,
  3.       h.descripcionh,
  4.       h.habit_x_hotel,
  5.       ho.descripcionho
  6.   FROM
  7.       habitacion h INNER JOIN hotel ho ON h.habit_x_hotel = ho.idhotel
  8.   WHERE
  9.       h.habit_x_hotel = '1'
  10.   ORDER BY h.habitacionh DESC) T1
  11. GROUP BY idhabitacion
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)

Etiquetas: mysql+consulta
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 14:30.