0

我有一张这样的桌子:

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"
4

1 回答 1

1

SELECT * FROM people WHERE second_name IN (SELECT second_name FROM people WHERE name=:first_name)

于 2013-02-17T18:19:11.207 回答