【问题标题】:Retrieving data from same table where multiple columns match in multiple rows从多列匹配多行的同一个表中检索数据
【发布时间】:2018-01-29 06:10:26
【问题描述】:

我有一个数据表,在这种情况下,一行的 id 变成了另一行的引用 id。下表如下。

我尝试如下检索数据,

select * from table1 t where t.id = t.reference_id

但它返回空表。

【问题讨论】:

  • 你应该尝试自我加入..
  • 像这样:- select * from table1 inner join table1 h on t.id = t.reference_id
  • 同时指定预期结果。请格式化文本! (即没有图像....)

标签: mysql sql select where


【解决方案1】:

尝试自我加入:

select * from table1 t1
inner join table1 t2 on t1.id = t2.reference_id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-22
    • 2023-02-03
    • 2019-04-30
    相关资源
    最近更新 更多