2014-12-02 64 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