开发者

Select query and unknow predicate value

I have this table with this columns: Key,Type,Culture.

Key and Culture are PK.

I know the Key and Culture values before query execution.

select * from resources r where r.CULTURE = 'sk' and r.KEY = 'test'; 

But I开发者_如何学JAVA'd like to perform a select which would select also all other records with the same Type as the record with Culture = 'sk' and Key = 'test'


SELECT * FROM resources AS r WHERE r.type =
(SELECT type FROM resources s  where s.culture= 'sk' and s.key= 'test')

culture and key are PK, so you only get one value back for type for your subquery. That result is used to get all rows with that type. If the subquery would return multiple values, you can use IN instead of =.


Use a join, it could resolves performance issue.

SELECT r.*
FROM resources r
    INNER JOIN resources r2
        ON r.type = r2.type
WHERE r2.CULTURE = 'sk' 
AND r2.KEY = 'test'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜