Hi folks,
So i'm having this problem.
I have two tables (Oracle), one is called Destination and the other one Reserve. Reserve has a foreign key to the id of Destination (Because on reserve has one destination). And reserve tuples means all the reserves that all the users have done. I need a way to check the top 3 most visited Destinations (based on the foreign key in the table Reserve).
How can I do that with SQL in Oracle. I know that I need to search within the Reserve tables for the 3 most repeated Destinations ID's, and later join that with the Destination table to get the details of the top 3 destinations.
Any help is valid. Thank you very much.
SCHEMA:
--------------------------------------------------------
-- File created - martes-septiembre-15-2009
--------------------------------------------------------
--------------------------------------------------------
-- DDL for Table DESTINO
--------------------------------------------------------
CREATE TABLE "S2501A29"."DESTINO"
( "PK_ID_DESTINO" NUMBER(10,0),
"FK_COD_UBICACION_GEOGRAFICA" NUMBER(10,0),
"NOMBRE" VARCHAR2(10),
"FOTO" VARCHAR2(30),
"DESCRIPCION" VARCHAR2(50)
) ;
--------------------------------------------------------
-- DDL for Table LUGAR_ESTADIA
--------------------------------------------------------
CREATE TABLE "S2501A29"."LUGAR_ESTADIA"
( "PK_ID_ESTADIA" NUMBER(10,0),
"NOMBRE" VARCHAR2(10),
"TIPO" VARCHAR2(10),
"DESCRIPCION" VARCHAR2(50),
"COSTO_SERVICIOS" NUMBER,
"DESCRIPCION_ALOJAMIENTO" VARCHAR2(100),
"DESCRIPCION_ALIMENTACION" VARCHAR2(100)
) ;
--------------------------------------------------------
-- DDL for Table OPCION_TRANSPORTE
--------------------------------------------------------
CREATE TABLE "S2501A29"."OPCION_TRANSPORTE"
( "PK_ID_VIAJE" NUMBER(10,0),
"MEDIO_TRANSPORTE" VARCHAR2(10),
"RESPONSABLE" VARCHAR2(10),
"CIUDAD_ORIGEN" VARCHAR2(10),
"CIUDAD_DESTINO" VARCHAR2(10),
"COSTO" NUMBER
) ;
--------------------------------------------------------
-- DDL for Table RESERVA
--------------------------------------------------------
CREATE TABLE "S2501A29"."RESERVA"
( "PK_ID_RESERVA" NUMBER(10,0),
"FK_COD_DESTINO" NUMBER(10,0),
"FK_COD_ESTADIA" NUMBER(10,0),
"FK_COD_VIAJE" NUMBER(10,0),
"TARJETA_CREDITO" VARCHAR2(12),
"FECHA_SALIDA" DATE,
"FECHA_REGRESO" DATE,
"NOMBRE_USUARIO" VARCHAR2(50)
) ;
--------------------------------------------------------
-- DDL for Table UBICACION_GEOGRAFICA
--------------------------------------------------------
CREATE TABLE "S2501A29"."UBICACION_GEOGRAFICA"
( "PK_ID_UBICACION" NUMBER(10,0),
"CIUDAD" VARCHAR2(10),
"PAIS" VARCHAR2(10),
"CONTINENTE" VARCHAR2(10)
) ;
Just a note:
RESERVE is Reserva DESTINATION is Destino
Because the DB is in spanish. Thanks!