如何选择具有与已知行相同列值的行?

5

这是一个表格:

    create table table1 (
        id integer primary key,
        user_id varchar(36),
        field1 varchar(100))

如何选择与特定id行所属的用户相关联的行。我想能够查看行,通过id选择消息,并选择所有与同一用户相关联的行。

    select * from table1
        where user_id = -- the same as of the row with id = 3 for example
2个回答

14

1

不确定这是哪种 SQL,但在 SQL Server 中:

select * from table1
where user_id = (select user_id from table1 where id = 3)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接