2014-09-30 63 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; 
相关问题