2014-12-02 117 views
0

我有两个表。 Table_1有这个字段。MySQL查询不返回任何内容或返回错误的数据

table_1_id 
name 
image 
adres 

TABLE_2

table_2_id 
name 
email 
phone 
comment 
datetime 
need_id 

我要让我的ID_1形式table_1点击加载我从table_2具有table_1_id = 1 我与此查询

SELECT t1*, t2.* FROM table_1 t1, table_2 t2 
       WHERE t1.table_1_id = t2.need_id ORDER BY `DateTime` DESC 
尝试了所有行

并显示空白页。然后我试图这样

SELECT t1.*, t2.* FROM table_1 t1 
JOIN table_2 t2 ON t1.table_1_id = t2.need_id ORDER BY ` DateTime` DESC 

这一切我点击返回从数据库中第一条结果就是这样。

回答

1

假设你有ID_1,你并不需要在查询中涉及table_1

SELECT * FROM table_2 
WHERE need_id = ID_1 
ORDER BY `DateTime` DESC 
+0

它的工作完美。谢谢! – 2014-12-02 15:18:24