1. 程式人生 > >MySql資料庫查詢(五)——合併查詢

MySql資料庫查詢(五)——合併查詢

1.合併查詢結果

將兩張表的資料合併在一起

先檢視兩張表的內容:select * from t_book;

select * from t_booktype;

將兩張表的id屬性合併,有:

select id from t_book union select id from t_booktype;

若想合併後不消除共同屬性有:

select id from t_book union all select id from t_booktype;

2.為表和欄位取別名

2.1為表取別名

表名  表別名;

select * from t_book where id=1;

取別名:select * from t_book tb where tb.id=1;

查詢結果是一樣的;

2.2為欄位取別名

屬性名 [AS] 別名

select bookName as bn from t_book tb where tb.id=1;