query relating two unrelated tables

0

I have an sql query that leads me, I have two tables not linked to each other, of which I want to select users whose year of birth is between the year of beginning of the category and the final year. These are the tables:

CREATE TABLE IF NOT EXISTS usuarios (   
   id_usuario          int(11) NOT NULL auto_increment, 
   use_nombre          varchar(50) COLLATE utf8_unicode_ci NULL, 
   use_apellidos       varchar(100) COLLATE utf8_unicode_ci NULL, 
   use_direccion       varchar(100) COLLATE utf8_unicode_ci NULL, 
   use_codigo_postal   int(5) NULL, 
   use_telefono1       int(9) NULL, 
   use_telefono2       int(9) NULL, 
   Use_año_nacimiento int(11)  NULL,   /* esta es la referencia */
   Use_DNI varchar(9)  NULL,  /* -- dni con letra */   
   PRIMARY KEY (Id_usuario)    ) 
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

Inquiry2:

CREATE TABLE IF NOT EXISTS categorias 
  ( 
     id_categoria          INT(11) NOT NULL auto_increment, 
     id_modalidad          INT(11) NOT NULL, 
     nombre_categoria      VARCHAR(50) CHARACTER SET utf8 COLLATE 
     utf8_unicode_ci       OT NULL, 
     año_inicio_categoria  INT(11) NULL, /* y estos son los campos que hay que utilizar para  el filtro */ 
     año_fin_categoria     int(11)  NULL 
     PRIMARY KEY (id_categoria) 
  ) 
engine=innodb DEFAULT charset=utf8 COLLATE=utf8_unicode_ci auto_increment=1; 

Greetings

    
asked by jose 30.06.2016 в 10:05
source

2 answers

1

In the absence of more information , I suggest putting together the following query (which I have not tried:)

SELECT usrs.use_nombre, usrs.use_apellidos, usrs.use_direccion, usrs.use_codigo_postal, usrs.Use_DNI
FROM usuarios AS usrs, categorias AS catgs
WHERE usrs.Use_año_nacimiento BETWEEN catgs.año_inicio_categoria AND catgs.año_fin_categoria
    
answered by 30.06.2016 в 13:32
-2

You will have to create a stored procedure, in which you declare a course, from which you obtain the years of the categories, and then launch that query on the users table

    
answered by 30.06.2016 в 11:15