我有一张这样的表:
user_id, name, second_name
示例数据:
1, "fred", "smith"
2, "john", "smith"
3, "karl", "johnson"
我想找到所有名字叫“fred”的人。然后我想找到所有与“Fred”具有相同名字的人。如果可能的话,我想在一个查询中执行此操作。与此类似的查询:
SELECT * FROM people WHERE name=:first_name OR second_name=:result_from_first_row
此示例查询的输出为:
1, "fred", "smith"
2, "john", "smith"
答案 0 :(得分:1)
SELECT * FROM people WHERE second_name IN(SELECT second_name FROM people WHERE name =:first_name)