如何选择列值等于已知行值的行?

Ale*_*lex 3 sql

这里有张桌子:

    create table table1 (
        id integer primary key,
        user_id varchar(36),
        field1 varchar(100))
Run Code Online (Sandbox Code Playgroud)

如何选择链接到用户的行,具有特定ID的行属于该行.我希望能够查看行,按ID选择消息并选择链接到同一用户的所有行.

    select * from table1
        where user_id = -- the same as of the row with id = 3 for example
Run Code Online (Sandbox Code Playgroud)

Pao*_*ino 11

使用子查询非常容易,特别是在文档中使用子查询进行比较:

SELECT * FROM table1 WHERE user_id = (SELECT user_id FROM table1 WHERE id = 3)
Run Code Online (Sandbox Code Playgroud)