2014-09-30 28 views
-1

我創建了兩個表:怎麼顯示兩個表中的記錄(所選列)

Name:table1,table2 

table1 consists of:id,name,contactnumber 
        101,john,9955443322 
        102,peter,9955443311 
table2 consists of:id,place,date 
        101,chennai,15-05-2014 
        102,munbai,13-05-2014 

select table1.id 
    ,table1.contactnumber 
    ,table2.date 
from table1,table2 
where table2.date = 29-09-2014 
    && table2.loannumbers=table1.loannumber 

歸來卻空空的結果集。

我想顯示的列:

id,name,date 

我想要顯示的行:

所有的
(table2)date=15-05-2014 and (table1)id=id(table2). 
+0

在你使用未在所提供的表結構列出的列查詢:'loadnumber',是正常的嗎? – 2014-09-30 08:20:46

回答

0

首先,不要使用該語法表之間jointures。這是一個老派的符號,使用明確的關節將會更加可讀。

這裏是你要找的查詢:

SELECT T1.id 
    ,T1.name 
    ,T2.date 
FROM table1 T1 
INNER JOIN table2 T2 ON T2.id = T1.id 
         AND T2.date = '2014-05-15' 

希望這會有所幫助。

+0

有錯誤未知列'table1.contactnumber'在'字段列表' – dsk 2014-09-30 08:33:56

+0

@dsk我基於我對你提供的表結構的查詢。你能否確認我在table1中存在àcolumn contactnumber? – 2014-09-30 08:38:17

+0

yes.contactnumber在mytable中。我對錯誤感到困惑。 – dsk 2014-09-30 08:44:20

0

試試這個

SELECT table1.id, table1.name, table2.date 
FROM table1 
INNER JOIN table2 ON table1.id = table2.id; 
相關問題