我有两张桌子。表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个结果,那就是它。
答案 0 :(得分:1)
假设您有ID_1
,则无需在查询中涉及table_1
:
SELECT * FROM table_2
WHERE need_id = ID_1
ORDER BY `DateTime` DESC