mysql支援多個庫中不同表的關聯查詢,你可以隨便連結一個數據庫
然後,sql語句為:
select * from db1.table1 left join db2.table2 on db1.table1.id = db2.table2.id
只要用資料庫名加上"."就能呼叫相應資料庫的資料表了.
資料庫名.表名
擴充套件資料
mysql查詢語句
1、查詢一張表: select * from 表名;
2、查詢指定欄位:select 欄位1,欄位2,欄位3....from 表名;
3、where條件查詢:select 欄位1,欄位2,欄位3 frome 表名 where 條件表示式;
例:select * from t_studect where id=1;
select * from t_student where age>22
4、帶in關鍵字查詢:select 欄位1,欄位2 frome 表名 where 欄位 [not]in(元素1,元素2);
例:select * from t_student where age in (21,23);
select * from t_student where age not in (21,23);
5、帶between and的範圍查詢:select 欄位1,欄位2 frome 表名 where 欄位 [not]between 取值1 and 取值2;
例:select * frome t_student where age between 21 and 29;
select * frome t_student where age not between 21 and 29;
mysql支援多個庫中不同表的關聯查詢,你可以隨便連結一個數據庫
然後,sql語句為:
select * from db1.table1 left join db2.table2 on db1.table1.id = db2.table2.id
只要用資料庫名加上"."就能呼叫相應資料庫的資料表了.
資料庫名.表名
擴充套件資料
mysql查詢語句
1、查詢一張表: select * from 表名;
2、查詢指定欄位:select 欄位1,欄位2,欄位3....from 表名;
3、where條件查詢:select 欄位1,欄位2,欄位3 frome 表名 where 條件表示式;
例:select * from t_studect where id=1;
select * from t_student where age>22
4、帶in關鍵字查詢:select 欄位1,欄位2 frome 表名 where 欄位 [not]in(元素1,元素2);
例:select * from t_student where age in (21,23);
select * from t_student where age not in (21,23);
5、帶between and的範圍查詢:select 欄位1,欄位2 frome 表名 where 欄位 [not]between 取值1 and 取值2;
例:select * frome t_student where age between 21 and 29;
select * frome t_student where age not between 21 and 29;