开发者

How to use the result of a query in another select statement?

开发者 https://www.devze.com 2023-04-12 07:25 出处:网络
I have a table A, and it contains 10 rows and 3 columns. One of the columns is name and these are table names.

I have a table A, and it contains 10 rows and 3 columns. One of the columns is name and these are table names.

I have written a query

select name from A

Now iIwant to use the value of all 10 names (as table names) in other query. How开发者_如何学编程 can I do this in Sybase?


You can use a result set for a JOIN

SELECT [B].*
FROM [B]
    INNER JOIN (SELECT [Name] FROM [A]) aliasA
    ON [B].[Name] = aliasA.[Name]

or you can use a result set for a WHERE

SELECT [B].*
FROM [B]
WHERE [B].[Name] IN 
    (SELECT [Name] FROM [A])

You can also use it in a variety of other ways. In most scenarios you can treat a result set as though it were a table - select from it, join with it, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消