Query is the core of the database, the following for you to introduce MySQL multiple table query How to achieve, if you are in the MySQL multiple table query has encountered problems, may wish to see.
mysql multiple table query:
Copy Code code as follows:
CREATE TABLE IF not EXISTS contacts (
contact_id Int (one) not NULL auto_increment,
User_name varchar (255),
Nom varchar (255),
Prenom varchar (255),
Mail varchar (64),
Passcode char (64),
PRIMARY KEY (contact_id)
);
CREATE TABLE IF not EXISTS droit (
droit_id Int (one) not NULL auto_increment,
Droit varchar (255),
PRIMARY KEY (droit_id)
);
CREATE TABLE IF not EXISTS contactdroit (
contactdroit_id Int (one) not NULL auto_increment,
contact_id Int (11),
droit_id Int (11),
PRIMARY KEY (contactdroit_id)
);
Insert into Contacts (contact_id, user_name) VALUES (1, ' User1 ');
Insert into Contacts (contact_id, user_name) VALUES (2, ' user2 ');
Insert into Contacts (contact_id, user_name) VALUES (3, ' User3 ');
Insert into Droit (droit_id, Droit) VALUES (1, ' admin ');
Insert into Droit (droit_id, Droit) values (2, ' superuser ');
Insert into Contactdroit (contact_id, droit_id) VALUES (1, 1);
Insert into Contactdroit (contact_id, droit_id) VALUES (2, 1);
Insert into Contactdroit (contact_id, droit_id) VALUES (3, 2);
SELECT c.contact_id, d.droit_id, d.droit from contacts C, Contactdroit CD, Droit d
where c.contact_id = cd.contact_id
and cd.droit_id = d.droit_id;
Results:
Copy Code code as follows:
contact_id droit_id Droit
1 1 Admin
2 1 Admin
3 2 Superuser
The above is the MySQL multiple table query implementation method.