2009-05-04 60 views
3

有一個表:如何選擇列值等於已知行值的行?

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 

回答

1

不知道SQL這只是在SQL Server:

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