Wednesday 15 February 2012

sql - Querying a table matching all the data of the subquery and all the data should also match with common data -



sql - Querying a table matching all the data of the subquery and all the data should also match with common data -

i have 2 tables called "membership" , "restricted".

table: membership

+---------+--------+ | groupid | userid | +---------+--------+ | 10001 | 605 | | 10001 | 255 | | 10002 | 605 | | 10004 | 222 | | 10003 | 605 | | 10002 | 501 | +---------+--------+

table: restriction table called restriction having restricted groupid , corresponding contentid grouping restricted.

+---------+-----------+ | groupid | contentid | +---------+-----------+ | 10001 | 33333 | | 10001 | 22222 | | 10002 | 22222 | | 10004 | 44444 | | 10003 | 22222 | | 10002 | 44444 | +---------+-----------+

i want contentid of grouping user id belong restricted table.

ie. in sample info userid = 605, grouping ids "10001, 10002, 10003", need contentid restricted grouping id listed user 605.

the expected contentid in case '22222'.

the ultimate aim list of contentid's restricted in grouping userid. if contentid not restricted in 1 of grouping contentid no more considered restricted.

best can without knowing table structures:

select contentid, * [databasename].dbo.members m bring together [databasename].dbo.restricted r on r.groupid = m.groupid m.groupid = 505

sql sql-server

No comments:

Post a Comment