自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Mysql多表查詢的實(shí)現(xiàn)

數(shù)據(jù)庫 MySQL
在Mysql數(shù)據(jù)庫中,有多種查詢的方式,可以滿足我們不同的需要,下面就為您介紹Mysql多表查詢的實(shí)現(xiàn)方法,供您參考。

查詢是數(shù)據(jù)庫的核心,下面就為您介紹Mysql多表查詢時如何實(shí)現(xiàn)的,如果您在Mysql多表查詢方面遇到過問題,不妨一看。

Mysql多表查詢:

  1. CREATE TABLE IF NOT EXISTS contact(  
  2. contact_id int(11) NOT NULL AUTO_INCREMENT,  
  3. user_name varchar(255),  
  4. nom varchar(255),  
  5. prenom varchar(255),  
  6. mail varchar(64),  
  7. passcode char(64),  
  8. PRIMARY KEY(contact_id)  
  9. );  
  10. CREATE TABLE IF NOT EXISTS droit(  
  11. droit_id int( 11 ) NOT NULL AUTO_INCREMENT ,  
  12. droit varchar(255),  
  13. PRIMARY KEY(droit_id)  
  14. );  
  15. CREATE TABLE IF NOT EXISTS contactdroit(  
  16. contactdroit_id int(11) NOT NULL AUTO_INCREMENT,  
  17. contact_id int( 11 ),  
  18. droit_id int( 11 ),  
  19. PRIMARY KEY( contactdroit_id )  
  20. );  
  21. Insert into contact(contact_id, user_name) values(1,'user1');  
  22. Insert into contact(contact_id, user_name) values(2,'user2');  
  23. Insert into contact(contact_id, user_name) values(3,'user3');  
  24. Insert into droit(droit_id, droit) values(1,'admin');  
  25. Insert into droit(droit_id, droit) values(2,'superuser');  
  26. Insert into contactdroit(contact_id, droit_id) values(1, 1);  
  27. Insert into contactdroit(contact_id, droit_id) values(2, 1);  
  28. Insert into contactdroit(contact_id, droit_id) values(3, 2);  
  29.  
  30. SELECT c.contact_id, d.droit_id, d.droit FROM contact c, contactdroit cd, droit d   
  31. where c.contact_id = cd.contact_id  
  32. and cd.droit_id = d.droit_id;  

結(jié)果:

  1. contact_id     droit_id     droit  
  2. 1                      1           admin  
  3. 2                      1           admin  
  4. 3                  2          superuser  

以上就是Mysql多表查詢的實(shí)現(xiàn)方法。

 

 

【編輯推薦】

MySQL CONVERT函數(shù)簡介

帶您了解mysql變量

撤權(quán)并刪除MySQL用戶的方法

教您如何實(shí)現(xiàn)MySQL動態(tài)視圖

MySQL查詢亂碼的解決方法

責(zé)任編輯:段燃 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-11-22 15:56:34

Mysql多表查詢

2010-11-22 15:34:17

MySQL多表更新

2010-10-15 15:02:37

Mysql多表刪除

2010-11-23 14:40:04

MySQL多表刪除

2010-11-23 11:44:10

MySQL多表聯(lián)合查詢

2012-07-06 09:00:34

MySQL

2022-04-01 11:14:48

MySQLJava索引

2024-05-09 08:20:29

AC架構(gòu)數(shù)據(jù)庫冗余存儲

2022-03-04 12:09:25

SQL數(shù)據(jù)量多表查詢

2010-10-14 14:33:15

MySQL多表聯(lián)查

2009-09-22 15:26:30

Hibernate多表

2010-11-22 16:05:53

MySQL多表插入

2009-09-15 10:35:11

linq多表查詢

2010-10-28 16:42:04

oracle多表查詢

2010-04-12 17:47:01

Oracle多表查詢

2010-05-07 11:00:25

Oracle多表查詢

2009-09-17 18:05:15

linq to sql

2009-06-18 13:58:06

Hibernate多表Hibernate

2010-06-02 18:07:44

MySQL數(shù)據(jù)庫

2010-11-25 14:52:35

MySQL隨機(jī)查詢
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號