我有两个表。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