本文目錄一覽:
mysql兩個資料庫的表能連接查詢嗎?
可以,前面加上模式名就行了
select *
from 資料庫1.tablename, 資料庫2.tablename
where 鏈接條件。
這是一個在我本機上跑過的例子,沒有鏈接條件,是個笛卡爾積:
select * from hibernate.card_t,wedb.article_t
mysql中同時查詢兩個資料庫中的數據
mysql中,可用庫名前綴同時查詢兩個資料庫中的數據。
工具:mysql
5.6
步驟:
1、如圖可見,在本地localhost中有2個資料庫,分別是badkano和badkano_test。
2、假如兩個資料庫中有相同的表student,數據分別如下:
3、要同時查詢兩個資料庫中的上邊兩張表,語句如下:
select * from badkano.student
union all
select * from badkano_test.student;4、查詢結果就將2個庫中的數據一起查出來了:
兩張表在不同的資料庫,如何關聯查詢?
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 age22
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;
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/190022.html