I would like to create a matrix with two tables in sql in the following way:
I have a table that contains the data:
id | name
00 | Form 0
01 | Form 1
02 | Form 2
03 | Form 3
04 | Form 4
another table:
id | name
00 | person.0
01 | person.1
02 | person.2
03 | person.3
04 | persona.4
id | person | id form
00 | 00 | 02
01 | 00 | 03
02 | 00 | 04
03 | 01 | 04
04 | 02 | 02
05 | 03 | 01
06 | 03 | 04
and that the result of the query is:
NOTE : If to do it with MySQL a lot of resource is consumed that is not necessary and it is better to do a basic query and create the matrix with the other language, I use PHP AND JQUERY , sending everything from php to jquery by < strong> JSON
create table formularios(
id int NOT NULL AUTO_INCREMENT,
nombre varchar(20),
PRIMARY KEY (id)
);
create table personas(
id int NOT NULL AUTO_INCREMENT,
nombre varchar(20),
PRIMARY KEY (id)
);
create table relacion(
id int NOT NULL AUTO_INCREMENT,
persona int,
formulario int,
PRIMARY KEY (id),
FOREIGN KEY (persona) REFERENCES personas(id),
FOREIGN KEY (formulario) REFERENCES formularios(id),
);