2016-09-19 30 views
-2

我在Microsoft Access中有2個表。需要幫助查找2個表之間的數據

1表名 - 在第一個表的代碼

我有超過15列,我需要插入10列一列後,和標題命名爲「類型」 - 詳細介紹 第二表名。第二個表中的 我有5欄。

每個表中的常見列是分析代碼。

表1

+-------+-------+---------------+------------+---------+ 
| Test1 | test2 | Analysis code | test4 | test5 | 
+-------+-------+---------------+------------+---------+ 
| ab | dfd | TON   | fddafd  | 212132 | 
| ced | fd | SIN   | 2133  | dfd2fd1 | 
| ef | fdfd | TON   | df2df1d31f | dfd3sa3 | 
| gh | dfd | SIN   | dfd63  | c22  | 
+-------+-------+---------------+------------+---------+ 

表2

+----------+---------------+----------+------------------------+ 
| sample 1 | Analysis code | sample 3 |   Type   | 
+----------+---------------+----------+------------------------+ 
| 558825 | TON   | a  | Terminated on network | 
| 258c  | SIN   | b  | International network | 
| 5856c | TOF   | c  | Terminated off network | 
| a21c5b | SMS   | d  | text message   | 
+----------+---------------+----------+------------------------+  

OUT PUT表

+-------+-------+---------------+-----------------------+------------+---------+ 
| Test1 | test2 | Analysis code |   Type   | test4 | test5 | 
+-------+-------+---------------+-----------------------+------------+---------+ 
| ab | dfd | TON   | Terminated on network | fddafd  | 212132 | 
| ced | fd | SIN   | International network | 2133  | dfd2fd1 | 
| ef | fdfd | TON   | Terminated on network | df2df1d31f | dfd3sa3 | 
| gh | dfd | SIN   | International network | dfd63  | c22  | 
+-------+-------+---------------+-----------------------+------------+---------+ 
+3

使用格式化工具爲了使您的文章更「可讀」,我什至不知道你的問題。 – LostReality

+0

http://ozh.github.io/ascii-tables/查看樣本數據。 – Andre

回答

0

你需要加入相應的列在表1和表2。在你的情況「分析代碼」

的樣本是:

SELECT Test1, test2, [table1.Analysis code], table2.type .... rest 
FROM table1 left join table2 on table1.[Analysis code] = tble2.[analysis code] 

上面的SQL代碼將產生[有些]您的預計產出表。話雖如此,請允許我建議,您需要閱讀更多關於SQL語言和[關係數據庫]的信息。將幫助你更多!

+0

在上面的例子中,我只給出了5列,但我有超過20列,在這種情況下,我是否需要更新表1中的所有列名稱,替換上面的代碼右邊的其餘部分... 如果你不介意,你可以請完成上面的代碼,而不更新那裏的其餘部分,這樣我就可以在Access中得到一些關於我的數據庫的想法。請做有需要的人。謝謝。 – Giri