MySQL查询不返回任何内容或返回错误的数据

时间:2014-12-02 15:11:34

标签: php mysql

我有两张桌子。表1包含此字段。

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 

无论我点击什么,都会从数据库返回前5个结果,那就是它。

1 个答案:

答案 0 :(得分:1)

假设您有ID_1,则无需在查询中涉及table_1

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