有一张桌子:
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
答案 0 :(得分:10)
使用subqueries非常简单,特别是文档中的Comparisons Using Subqueries:
SELECT * FROM table1 WHERE user_id = (SELECT user_id FROM table1 WHERE id = 3)
答案 1 :(得分:1)
不确定这是什么SQL,但在SQL Server中:
select * from table1
where user_id = (select user_id from table1 where id = 3)