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


MySQL query doesn't return anything or return wrong data

我有两个表。Table_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 个结果,仅此而已。

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

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